{"id":815630,"url":"http://patchwork.ozlabs.org/api/patches/815630/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/patch/20170919155700.14474-2-vivien.didelot@savoirfairelinux.com/","project":{"id":7,"url":"http://patchwork.ozlabs.org/api/projects/7/?format=json","name":"Linux network development","link_name":"netdev","list_id":"netdev.vger.kernel.org","list_email":"netdev@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170919155700.14474-2-vivien.didelot@savoirfairelinux.com>","list_archive_url":null,"date":"2017-09-19T15:56:57","name":"[net-next,1/4] net: dsa: remove copy of master ethtool_ops","commit_ref":null,"pull_url":null,"state":"accepted","archived":true,"hash":"a4c360cc40ebb7d4e7f48781d41ac65dfea10565","submitter":{"id":15889,"url":"http://patchwork.ozlabs.org/api/people/15889/?format=json","name":"Vivien Didelot","email":"vivien.didelot@savoirfairelinux.com"},"delegate":{"id":34,"url":"http://patchwork.ozlabs.org/api/users/34/?format=json","username":"davem","first_name":"David","last_name":"Miller","email":"davem@davemloft.net"},"mbox":"http://patchwork.ozlabs.org/project/netdev/patch/20170919155700.14474-2-vivien.didelot@savoirfairelinux.com/mbox/","series":[{"id":3916,"url":"http://patchwork.ozlabs.org/api/series/3916/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/list/?series=3916","date":"2017-09-19T15:56:59","name":"net: dsa: move master ethtool code","version":1,"mbox":"http://patchwork.ozlabs.org/series/3916/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/815630/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/815630/checks/","tags":{},"related":[],"headers":{"Return-Path":"<netdev-owner@vger.kernel.org>","X-Original-To":"patchwork-incoming@ozlabs.org","Delivered-To":"patchwork-incoming@ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netdev-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xxSKP6zKFz9s7g\n\tfor <patchwork-incoming@ozlabs.org>;\n\tWed, 20 Sep 2017 02:01:13 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1751810AbdISQAs (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tTue, 19 Sep 2017 12:00:48 -0400","from mail.savoirfairelinux.com ([208.88.110.44]:46204 \"EHLO\n\tmail.savoirfairelinux.com\" rhost-flags-OK-OK-OK-OK) by\n\tvger.kernel.org with ESMTP id S1751378AbdISQAq (ORCPT\n\t<rfc822;netdev@vger.kernel.org>); Tue, 19 Sep 2017 12:00:46 -0400","from localhost (localhost [127.0.0.1])\n\tby mail.savoirfairelinux.com (Postfix) with ESMTP id 85C479C2CA9;\n\tTue, 19 Sep 2017 12:00:45 -0400 (EDT)","from mail.savoirfairelinux.com ([127.0.0.1])\n\tby localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new,\n\tport 10032)\n\twith ESMTP id 1PYzXQmWgJ5D; Tue, 19 Sep 2017 12:00:44 -0400 (EDT)","from localhost (localhost [127.0.0.1])\n\tby mail.savoirfairelinux.com (Postfix) with ESMTP id C52789C2CA8;\n\tTue, 19 Sep 2017 12:00:44 -0400 (EDT)","from mail.savoirfairelinux.com ([127.0.0.1])\n\tby localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new,\n\tport 10026)\n\twith ESMTP id c12UW-_cowsf; Tue, 19 Sep 2017 12:00:44 -0400 (EDT)","from weeman.mtl.sfl (unknown [192.168.49.104])\n\tby mail.savoirfairelinux.com (Postfix) with ESMTPSA id 9ADB39C2C65;\n\tTue, 19 Sep 2017 12:00:44 -0400 (EDT)"],"X-Virus-Scanned":"amavisd-new at mail.savoirfairelinux.com","From":"Vivien Didelot <vivien.didelot@savoirfairelinux.com>","To":"netdev@vger.kernel.org","Cc":"linux-kernel@vger.kernel.org, kernel@savoirfairelinux.com,\n\t\"David S. Miller\" <davem@davemloft.net>,\n\tFlorian Fainelli <f.fainelli@gmail.com>, Andrew Lunn <andrew@lunn.ch>,\n\tVivien Didelot <vivien.didelot@savoirfairelinux.com>","Subject":"[PATCH net-next 1/4] net: dsa: remove copy of master ethtool_ops","Date":"Tue, 19 Sep 2017 11:56:57 -0400","Message-Id":"<20170919155700.14474-2-vivien.didelot@savoirfairelinux.com>","X-Mailer":"git-send-email 2.14.1","In-Reply-To":"<20170919155700.14474-1-vivien.didelot@savoirfairelinux.com>","References":"<20170919155700.14474-1-vivien.didelot@savoirfairelinux.com>","Sender":"netdev-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netdev.vger.kernel.org>","X-Mailing-List":"netdev@vger.kernel.org"},"content":"There is no need to store a copy of the master ethtool ops, storing the\noriginal pointer in DSA and the new one in the master netdev itself is\nenough.\n\nIn the meantime, set orig_ethtool_ops to NULL when restoring the master\nethtool ops and check the presence of the master original ethtool ops as\nwell as its needed functions before calling them.\n\nSigned-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>\n---\n include/net/dsa.h |  1 -\n net/dsa/dsa.c     |  8 ++++----\n net/dsa/slave.c   | 19 +++++++++++--------\n 3 files changed, 15 insertions(+), 13 deletions(-)","diff":"diff --git a/include/net/dsa.h b/include/net/dsa.h\nindex dd44d6ce1097..8dee216a5a9b 100644\n--- a/include/net/dsa.h\n+++ b/include/net/dsa.h\n@@ -188,7 +188,6 @@ struct dsa_port {\n \t/*\n \t * Original copy of the master netdev ethtool_ops\n \t */\n-\tstruct ethtool_ops\tethtool_ops;\n \tconst struct ethtool_ops *orig_ethtool_ops;\n };\n \ndiff --git a/net/dsa/dsa.c b/net/dsa/dsa.c\nindex 03c58b0eb082..abadf7b49236 100644\n--- a/net/dsa/dsa.c\n+++ b/net/dsa/dsa.c\n@@ -124,11 +124,10 @@ int dsa_cpu_port_ethtool_setup(struct dsa_port *cpu_dp)\n \tif (!cpu_ops)\n \t\treturn -ENOMEM;\n \n-\tmemcpy(&cpu_dp->ethtool_ops, master->ethtool_ops,\n-\t       sizeof(struct ethtool_ops));\n \tcpu_dp->orig_ethtool_ops = master->ethtool_ops;\n-\tmemcpy(cpu_ops, &cpu_dp->ethtool_ops,\n-\t       sizeof(struct ethtool_ops));\n+\tif (cpu_dp->orig_ethtool_ops)\n+\t\tmemcpy(cpu_ops, cpu_dp->orig_ethtool_ops, sizeof(*cpu_ops));\n+\n \tdsa_cpu_port_ethtool_init(cpu_ops);\n \tmaster->ethtool_ops = cpu_ops;\n \n@@ -138,6 +137,7 @@ int dsa_cpu_port_ethtool_setup(struct dsa_port *cpu_dp)\n void dsa_cpu_port_ethtool_restore(struct dsa_port *cpu_dp)\n {\n \tcpu_dp->netdev->ethtool_ops = cpu_dp->orig_ethtool_ops;\n+\tcpu_dp->orig_ethtool_ops = NULL;\n }\n \n void dsa_cpu_dsa_destroy(struct dsa_port *port)\ndiff --git a/net/dsa/slave.c b/net/dsa/slave.c\nindex 2afa99506f8b..2ff4f907d137 100644\n--- a/net/dsa/slave.c\n+++ b/net/dsa/slave.c\n@@ -574,12 +574,13 @@ static void dsa_cpu_port_get_ethtool_stats(struct net_device *dev,\n \tstruct dsa_switch_tree *dst = dev->dsa_ptr;\n \tstruct dsa_port *cpu_dp = dsa_get_cpu_port(dst);\n \tstruct dsa_switch *ds = cpu_dp->ds;\n+\tconst struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops;\n \ts8 cpu_port = cpu_dp->index;\n \tint count = 0;\n \n-\tif (cpu_dp->ethtool_ops.get_sset_count) {\n-\t\tcount = cpu_dp->ethtool_ops.get_sset_count(dev, ETH_SS_STATS);\n-\t\tcpu_dp->ethtool_ops.get_ethtool_stats(dev, stats, data);\n+\tif (ops && ops->get_sset_count && ops->get_ethtool_stats) {\n+\t\tcount = ops->get_sset_count(dev, ETH_SS_STATS);\n+\t\tops->get_ethtool_stats(dev, stats, data);\n \t}\n \n \tif (ds->ops->get_ethtool_stats)\n@@ -591,10 +592,11 @@ static int dsa_cpu_port_get_sset_count(struct net_device *dev, int sset)\n \tstruct dsa_switch_tree *dst = dev->dsa_ptr;\n \tstruct dsa_port *cpu_dp = dsa_get_cpu_port(dst);\n \tstruct dsa_switch *ds = cpu_dp->ds;\n+\tconst struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops;\n \tint count = 0;\n \n-\tif (cpu_dp->ethtool_ops.get_sset_count)\n-\t\tcount += cpu_dp->ethtool_ops.get_sset_count(dev, sset);\n+\tif (ops && ops->get_sset_count)\n+\t\tcount += ops->get_sset_count(dev, sset);\n \n \tif (sset == ETH_SS_STATS && ds->ops->get_sset_count)\n \t\tcount += ds->ops->get_sset_count(ds);\n@@ -608,6 +610,7 @@ static void dsa_cpu_port_get_strings(struct net_device *dev,\n \tstruct dsa_switch_tree *dst = dev->dsa_ptr;\n \tstruct dsa_port *cpu_dp = dsa_get_cpu_port(dst);\n \tstruct dsa_switch *ds = cpu_dp->ds;\n+\tconst struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops;\n \ts8 cpu_port = cpu_dp->index;\n \tint len = ETH_GSTRING_LEN;\n \tint mcount = 0, count;\n@@ -619,9 +622,9 @@ static void dsa_cpu_port_get_strings(struct net_device *dev,\n \t/* We do not want to be NULL-terminated, since this is a prefix */\n \tpfx[sizeof(pfx) - 1] = '_';\n \n-\tif (cpu_dp->ethtool_ops.get_sset_count) {\n-\t\tmcount = cpu_dp->ethtool_ops.get_sset_count(dev, ETH_SS_STATS);\n-\t\tcpu_dp->ethtool_ops.get_strings(dev, stringset, data);\n+\tif (ops && ops->get_sset_count && ops->get_strings) {\n+\t\tmcount = ops->get_sset_count(dev, ETH_SS_STATS);\n+\t\tops->get_strings(dev, stringset, data);\n \t}\n \n \tif (stringset == ETH_SS_STATS && ds->ops->get_strings) {\n","prefixes":["net-next","1/4"]}