Module: xenomai-3
Branch: next
Commit: 27fbcff908d68f37e2bc1d3ba3535c1b267e4916
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=27fbcff908d68f37e2bc1d3ba3535c1b267e4916

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue Jan 23 12:03:51 2018 +0100

net/socket: align rtdev do_ioctl handler on the regular ndo_do_ioctl

Align on the signature of the regular ndo_do_ioctl() handler for
interface-directed ioctl requests, since an ifr block must have been
provided by the caller to determine the device to hand over the
request to anyway.

---

 kernel/drivers/net/drivers/8139too.c                 |    7 +++----
 .../net/drivers/experimental/rt2500/rt2x00core.c     |    6 +++---
 kernel/drivers/net/drivers/igb/igb_main.c            |    7 +++----
 kernel/drivers/net/stack/include/rtdev.h             |    2 +-
 kernel/drivers/net/stack/rtwlan.c                    |   18 ++++++++++++++----
 kernel/drivers/net/stack/socket.c                    |    4 ++--
 6 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/kernel/drivers/net/drivers/8139too.c 
b/kernel/drivers/net/drivers/8139too.c
index 8b1a7df..d49d779 100644
--- a/kernel/drivers/net/drivers/8139too.c
+++ b/kernel/drivers/net/drivers/8139too.c
@@ -519,7 +519,7 @@ static int rtl8139_close (struct rtnet_device *rtdev);
 static int rtl8139_interrupt (rtdm_irq_t *irq_handle);
 static int rtl8139_start_xmit (struct rtskb *skb, struct rtnet_device *rtdev);
 
-static int rtl8139_ioctl(struct rtnet_device *rtdev, unsigned int request, 
void *cmd);
+static int rtl8139_ioctl(struct rtnet_device *, struct ifreq *rq, int cmd);
 static struct net_device_stats *rtl8139_get_stats(struct rtnet_device*rtdev);
 
 static void rtl8139_init_ring (struct rtnet_device *rtdev);
@@ -1297,15 +1297,14 @@ static int rtl8139_start_xmit (struct rtskb *skb, 
struct rtnet_device *rtdev)
        return 0;
 }
 
-static int rtl8139_ioctl(struct rtnet_device *rtdev, unsigned int request, 
void *arg)
+static int rtl8139_ioctl(struct rtnet_device *rtdev, struct ifreq *ifr, int 
cmd)
 {
     struct rtl8139_private *tp = rtdev->priv;
     void *ioaddr = tp->mmio_addr;
     int nReturn = 0;
-    struct ifreq *ifr = arg;
     struct ethtool_value *value;
 
-    switch (request) {
+    switch (cmd) {
        case SIOCETHTOOL:
            /* TODO: user-safe parameter access, most probably one layer higher 
*/
            value = (struct ethtool_value *)ifr->ifr_data;
diff --git a/kernel/drivers/net/drivers/experimental/rt2500/rt2x00core.c 
b/kernel/drivers/net/drivers/experimental/rt2500/rt2x00core.c
index c4807ef..926c7de 100644
--- a/kernel/drivers/net/drivers/experimental/rt2500/rt2x00core.c
+++ b/kernel/drivers/net/drivers/experimental/rt2500/rt2x00core.c
@@ -112,15 +112,15 @@ static int rt2x00_radio_off(struct _rt2x00_core * core) {
 /*
  * user space io handler
  */
-static int rt2x00_ioctl(struct rtnet_device * rtnet_dev, unsigned int request, 
void * arg) {
-
+static int rt2x00_ioctl(struct rtnet_device *rtnet_dev, struct ifreq *ifr, int 
request)
+{
     struct rtwlan_device * rtwlan_dev  = rtnetdev_priv(rtnet_dev);
     struct _rt2x00_core * core     = rtwlan_priv(rtwlan_dev);
     struct rtwlan_cmd * cmd;
     u8 rate, dsss_rate, ofdm_rate;
     u32 address, value;
 
-    cmd = (struct rtwlan_cmd *)arg;
+    cmd = (struct rtwlan_cmd *)ifr->ifr_data;
 
     switch(request) {
 
diff --git a/kernel/drivers/net/drivers/igb/igb_main.c 
b/kernel/drivers/net/drivers/igb/igb_main.c
index fe0132b..be98d78 100644
--- a/kernel/drivers/net/drivers/igb/igb_main.c
+++ b/kernel/drivers/net/drivers/igb/igb_main.c
@@ -216,7 +216,7 @@ static int igb_msix_ring(rtdm_irq_t *irq_handle);
 static void igb_poll(struct igb_q_vector *);
 static bool igb_clean_tx_irq(struct igb_q_vector *);
 static bool igb_clean_rx_irq(struct igb_q_vector *, int);
-static int igb_ioctl(struct rtnet_device *, unsigned cmd, void *);
+static int igb_ioctl(struct rtnet_device *, struct ifreq *ifr, int cmd);
 static void igb_reset_task(struct work_struct *);
 static void igb_vlan_mode(struct rtnet_device *netdev,
                          netdev_features_t features);
@@ -5063,15 +5063,14 @@ static int igb_mii_ioctl(struct rtnet_device *netdev, 
struct ifreq *ifr, int cmd
  * @ifreq:
  * @cmd:
  **/
-static int igb_ioctl(struct rtnet_device *netdev, unsigned cmd, void *rq)
+static int igb_ioctl(struct rtnet_device *netdev, struct ifreq *ifr, int cmd)
 {
-       struct ifreq *ifr = rq;
-
        switch (cmd) {
        case SIOCGMIIPHY:
        case SIOCGMIIREG:
        case SIOCSMIIREG:
                return igb_mii_ioctl(netdev, ifr, cmd);
+
        default:
                return -EOPNOTSUPP;
        }
diff --git a/kernel/drivers/net/stack/include/rtdev.h 
b/kernel/drivers/net/stack/include/rtdev.h
index c1c0b4e..a3ac7dd 100644
--- a/kernel/drivers/net/stack/include/rtdev.h
+++ b/kernel/drivers/net/stack/include/rtdev.h
@@ -152,7 +152,7 @@ struct rtnet_device {
                                   unsigned int priority);
 
     int                 (*do_ioctl)(struct rtnet_device *rtdev,
-                                   unsigned int request, void * cmd);
+                                   struct ifreq *ifr, int cmd);
     struct net_device_stats *(*get_stats)(struct rtnet_device *rtdev);
 
     /* DMA pre-mapping hooks */
diff --git a/kernel/drivers/net/stack/rtwlan.c 
b/kernel/drivers/net/stack/rtwlan.c
index 2eb8ea1..dde6e55 100644
--- a/kernel/drivers/net/stack/rtwlan.c
+++ b/kernel/drivers/net/stack/rtwlan.c
@@ -121,11 +121,21 @@ int rtwlan_ioctl(struct rtnet_device * rtdev,
                 unsigned long arg)
 {
     struct rtwlan_cmd cmd;
+    struct ifreq ifr;
     int ret=0;
 
     if (copy_from_user(&cmd, (void *)arg, sizeof(cmd)) != 0)
        return -EFAULT;
 
+    /*
+     * FIXME: proper do_ioctl() should expect a __user pointer
+     * arg. This only works with the existing WLAN support because the
+     * only driver currently providing this feature is broken, not
+     * doing the copy_to/from_user dance.
+     */
+    memset(&ifr, 0, sizeof(ifr));
+    ifr.ifr_data = &cmd;
+   
     switch(request) {
     case IOC_RTWLAN_IFINFO:
        if (cmd.args.info.ifindex > 0)
@@ -141,7 +151,7 @@ int rtwlan_ioctl(struct rtnet_device * rtdev,
        }
 
        if (rtdev->do_ioctl)
-           ret = rtdev->do_ioctl(rtdev, request, &cmd);
+           ret = rtdev->do_ioctl(rtdev, &ifr, request);
        else
            ret = -ENORTWLANDEV;
 
@@ -168,11 +178,11 @@ int rtwlan_ioctl(struct rtnet_device * rtdev,
     case IOC_RTWLAN_BBPWRITE:
     case IOC_RTWLAN_BBPREAD:
     case IOC_RTWLAN_BBPSENS:
-       if (mutex_lock_interruptible(&rtdev->nrt_lock))
-           return -ERESTARTSYS;
+            if (mutex_lock_interruptible(&rtdev->nrt_lock))
+               return -ERESTARTSYS;
 
            if (rtdev->do_ioctl)
-               ret = rtdev->do_ioctl(rtdev, request, &cmd);
+               ret = rtdev->do_ioctl(rtdev, &ifr, request);
            else
                ret = -ENORTWLANDEV;
 
diff --git a/kernel/drivers/net/stack/socket.c 
b/kernel/drivers/net/stack/socket.c
index 1eb1856..c139d95 100644
--- a/kernel/drivers/net/stack/socket.c
+++ b/kernel/drivers/net/stack/socket.c
@@ -343,12 +343,12 @@ int rt_socket_if_ioctl(struct rtdm_fd *fd, int request, 
void __user *arg)
                if (rtdev->do_ioctl != NULL) {
                        if (rtdm_in_rt_context())
                                return -ENOSYS;
-                       ret = rtdev->do_ioctl(rtdev, request, arg);
+                       ret = rtdev->do_ioctl(rtdev, ifr, request);
                } else
                        ret = -EOPNOTSUPP;
            break;
 
-       default:
+        default:
            ret = -EOPNOTSUPP;
            break;
     }


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to