net: dsa: remove copy of master ethtool_ops
authorVivien Didelot <vivien.didelot@savoirfairelinux.com>
Tue, 19 Sep 2017 15:56:57 +0000 (11:56 -0400)
committerDavid S. Miller <davem@davemloft.net>
Tue, 19 Sep 2017 23:04:22 +0000 (16:04 -0700)
There is no need to store a copy of the master ethtool ops, storing the
original pointer in DSA and the new one in the master netdev itself is
enough.

In the meantime, set orig_ethtool_ops to NULL when restoring the master
ethtool ops and check the presence of the master original ethtool ops as
well as its needed functions before calling them.

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/dsa.h
net/dsa/dsa.c
net/dsa/slave.c

index dd44d6ce10976fa4d14a9b6086104c782cf5f40b..8dee216a5a9b1e2e40c435420e555253bb178ea1 100644 (file)
@@ -188,7 +188,6 @@ struct dsa_port {
        /*
         * Original copy of the master netdev ethtool_ops
         */
-       struct ethtool_ops      ethtool_ops;
        const struct ethtool_ops *orig_ethtool_ops;
 };
 
index 03c58b0eb082a5e5c125e2184bb29c80023cf017..abadf7b4923646d943cf9aa548bde473589ac30f 100644 (file)
@@ -124,11 +124,10 @@ int dsa_cpu_port_ethtool_setup(struct dsa_port *cpu_dp)
        if (!cpu_ops)
                return -ENOMEM;
 
-       memcpy(&cpu_dp->ethtool_ops, master->ethtool_ops,
-              sizeof(struct ethtool_ops));
        cpu_dp->orig_ethtool_ops = master->ethtool_ops;
-       memcpy(cpu_ops, &cpu_dp->ethtool_ops,
-              sizeof(struct ethtool_ops));
+       if (cpu_dp->orig_ethtool_ops)
+               memcpy(cpu_ops, cpu_dp->orig_ethtool_ops, sizeof(*cpu_ops));
+
        dsa_cpu_port_ethtool_init(cpu_ops);
        master->ethtool_ops = cpu_ops;
 
@@ -138,6 +137,7 @@ int dsa_cpu_port_ethtool_setup(struct dsa_port *cpu_dp)
 void dsa_cpu_port_ethtool_restore(struct dsa_port *cpu_dp)
 {
        cpu_dp->netdev->ethtool_ops = cpu_dp->orig_ethtool_ops;
+       cpu_dp->orig_ethtool_ops = NULL;
 }
 
 void dsa_cpu_dsa_destroy(struct dsa_port *port)
index 2afa99506f8b4f8ac051c5972acbf5dbd0c9bec3..2ff4f907d1372a6dcc72fac2eb47308d55e9f39c 100644 (file)
@@ -574,12 +574,13 @@ static void dsa_cpu_port_get_ethtool_stats(struct net_device *dev,
        struct dsa_switch_tree *dst = dev->dsa_ptr;
        struct dsa_port *cpu_dp = dsa_get_cpu_port(dst);
        struct dsa_switch *ds = cpu_dp->ds;
+       const struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops;
        s8 cpu_port = cpu_dp->index;
        int count = 0;
 
-       if (cpu_dp->ethtool_ops.get_sset_count) {
-               count = cpu_dp->ethtool_ops.get_sset_count(dev, ETH_SS_STATS);
-               cpu_dp->ethtool_ops.get_ethtool_stats(dev, stats, data);
+       if (ops && ops->get_sset_count && ops->get_ethtool_stats) {
+               count = ops->get_sset_count(dev, ETH_SS_STATS);
+               ops->get_ethtool_stats(dev, stats, data);
        }
 
        if (ds->ops->get_ethtool_stats)
@@ -591,10 +592,11 @@ static int dsa_cpu_port_get_sset_count(struct net_device *dev, int sset)
        struct dsa_switch_tree *dst = dev->dsa_ptr;
        struct dsa_port *cpu_dp = dsa_get_cpu_port(dst);
        struct dsa_switch *ds = cpu_dp->ds;
+       const struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops;
        int count = 0;
 
-       if (cpu_dp->ethtool_ops.get_sset_count)
-               count += cpu_dp->ethtool_ops.get_sset_count(dev, sset);
+       if (ops && ops->get_sset_count)
+               count += ops->get_sset_count(dev, sset);
 
        if (sset == ETH_SS_STATS && ds->ops->get_sset_count)
                count += ds->ops->get_sset_count(ds);
@@ -608,6 +610,7 @@ static void dsa_cpu_port_get_strings(struct net_device *dev,
        struct dsa_switch_tree *dst = dev->dsa_ptr;
        struct dsa_port *cpu_dp = dsa_get_cpu_port(dst);
        struct dsa_switch *ds = cpu_dp->ds;
+       const struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops;
        s8 cpu_port = cpu_dp->index;
        int len = ETH_GSTRING_LEN;
        int mcount = 0, count;
@@ -619,9 +622,9 @@ static void dsa_cpu_port_get_strings(struct net_device *dev,
        /* We do not want to be NULL-terminated, since this is a prefix */
        pfx[sizeof(pfx) - 1] = '_';
 
-       if (cpu_dp->ethtool_ops.get_sset_count) {
-               mcount = cpu_dp->ethtool_ops.get_sset_count(dev, ETH_SS_STATS);
-               cpu_dp->ethtool_ops.get_strings(dev, stringset, data);
+       if (ops && ops->get_sset_count && ops->get_strings) {
+               mcount = ops->get_sset_count(dev, ETH_SS_STATS);
+               ops->get_strings(dev, stringset, data);
        }
 
        if (stringset == ETH_SS_STATS && ds->ops->get_strings) {