net: provide a default dev->ethtool_ops
authorEric Dumazet <edumazet@google.com>
Sun, 16 Sep 2012 09:17:26 +0000 (09:17 +0000)
committerDavid S. Miller <davem@davemloft.net>
Wed, 19 Sep 2012 19:40:15 +0000 (15:40 -0400)
Instead of forcing device drivers to provide empty ethtool_ops or tweak
net/core/ethtool.c again, we could provide a generic ethtool_ops.

This occurred to me when I wanted to add GSO support to GRE tunnels.
ethtool -k support should be generic for all drivers.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Ben Hutchings <bhutchings@solarflare.com>
Cc: Maciej Żenczykowski <maze@google.com>
Reviewed-by: Ben Hutchings <bhutchings@solarflare.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/dev.c
net/core/ethtool.c

index bb42eb16196904f70c727c5385b21be45fef602c..bbda81997f4f418e8936c25b5c2122f7117bc91a 100644 (file)
@@ -5974,6 +5974,8 @@ struct netdev_queue *dev_ingress_queue_create(struct net_device *dev)
        return queue;
 }
 
+static const struct ethtool_ops default_ethtool_ops;
+
 /**
  *     alloc_netdev_mqs - allocate network device
  *     @sizeof_priv:   size of private data to allocate space for
@@ -6061,6 +6063,8 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
 
        strcpy(dev->name, name);
        dev->group = INIT_NETDEV_GROUP;
+       if (!dev->ethtool_ops)
+               dev->ethtool_ops = &default_ethtool_ops;
        return dev;
 
 free_all:
index cbf033dcaf1feb8b2cfc2610dad581e89bcdb061..4d64cc2e3fa9bf1246ea3504f582616f98060bf1 100644 (file)
@@ -1426,18 +1426,6 @@ int dev_ethtool(struct net *net, struct ifreq *ifr)
        if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
                return -EFAULT;
 
-       if (!dev->ethtool_ops) {
-               /* A few commands do not require any driver support,
-                * are unprivileged, and do not change anything, so we
-                * can take a shortcut to them. */
-               if (ethcmd == ETHTOOL_GDRVINFO)
-                       return ethtool_get_drvinfo(dev, useraddr);
-               else if (ethcmd == ETHTOOL_GET_TS_INFO)
-                       return ethtool_get_ts_info(dev, useraddr);
-               else
-                       return -EOPNOTSUPP;
-       }
-
        /* Allow some commands to be done by anyone */
        switch (ethcmd) {
        case ETHTOOL_GSET: