From patchwork Thu Jun 8 13:32:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuval Shaia X-Patchwork-Id: 773119 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3wk5wH0zfTz9s7p for ; Thu, 8 Jun 2017 23:33:19 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752505AbdFHNdP (ORCPT ); Thu, 8 Jun 2017 09:33:15 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:34837 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752022AbdFHNdN (ORCPT ); Thu, 8 Jun 2017 09:33:13 -0400 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v58DWeui001481 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 8 Jun 2017 13:32:41 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id v58DWcVj026151 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 8 Jun 2017 13:32:39 GMT Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v58DWZxd010846; Thu, 8 Jun 2017 13:32:36 GMT Received: from localhost.localdomain (/77.138.186.148) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 08 Jun 2017 06:32:35 -0700 From: Yuval Shaia To: davem@davemloft.net, andrew@lunn.ch, allan.nielsen@microsemi.com, Raju.Lakkaraju@microsemi.com, jakub.kicinski@netronome.com, steffen.klassert@secunet.com, ast@fb.com, sgruszka@redhat.com, mlichvar@redhat.com, yuval.shaia@oracle.com, netdev@vger.kernel.org Subject: [PATCH] net/ethtool: Replace memset with compiler directive Date: Thu, 8 Jun 2017 16:32:21 +0300 Message-Id: <20170608133221.608-1-yuval.shaia@oracle.com> X-Mailer: git-send-email 2.9.4 X-Source-IP: userv0022.oracle.com [156.151.31.74] Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Take advantage of compiler variable zero-ing and remove calls to memset. Signed-off-by: Yuval Shaia --- net/core/ethtool.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/net/core/ethtool.c b/net/core/ethtool.c index 03111a2..051af09 100644 --- a/net/core/ethtool.c +++ b/net/core/ethtool.c @@ -559,7 +559,7 @@ int __ethtool_get_link_ksettings(struct net_device *dev, struct ethtool_link_ksettings *link_ksettings) { int err; - struct ethtool_cmd cmd; + struct ethtool_cmd cmd = {0}; ASSERT_RTNL(); @@ -576,7 +576,6 @@ int __ethtool_get_link_ksettings(struct net_device *dev, if (!dev->ethtool_ops->get_settings) return -EOPNOTSUPP; - memset(&cmd, 0, sizeof(cmd)); cmd.cmd = ETHTOOL_GSET; err = dev->ethtool_ops->get_settings(dev, &cmd); if (err < 0) @@ -777,7 +776,7 @@ warn_incomplete_ethtool_legacy_settings_conversion(const char *details) */ static int ethtool_get_settings(struct net_device *dev, void __user *useraddr) { - struct ethtool_cmd cmd; + struct ethtool_cmd cmd = {0}; ASSERT_RTNL(); @@ -808,7 +807,6 @@ static int ethtool_get_settings(struct net_device *dev, void __user *useraddr) if (!dev->ethtool_ops->get_settings) return -EOPNOTSUPP; - memset(&cmd, 0, sizeof(cmd)); cmd.cmd = ETHTOOL_GSET; err = dev->ethtool_ops->get_settings(dev, &cmd); if (err < 0) @@ -870,10 +868,9 @@ static int ethtool_set_settings(struct net_device *dev, void __user *useraddr) static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev, void __user *useraddr) { - struct ethtool_drvinfo info; + struct ethtool_drvinfo info = {0}; const struct ethtool_ops *ops = dev->ethtool_ops; - memset(&info, 0, sizeof(info)); info.cmd = ETHTOOL_GDRVINFO; if (ops->get_drvinfo) { ops->get_drvinfo(dev, &info); @@ -916,7 +913,7 @@ static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev, static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev, void __user *useraddr) { - struct ethtool_sset_info info; + struct ethtool_sset_info info = {0}; u64 sset_mask; int i, idx = 0, n_bits = 0, ret, rc; u32 *info_buf = NULL; @@ -932,7 +929,6 @@ static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev, /* calculate size of return buffer */ n_bits = hweight64(sset_mask); - memset(&info, 0, sizeof(info)); info.cmd = ETHTOOL_GSSET_INFO; info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER); @@ -1479,13 +1475,12 @@ static int ethtool_set_wol(struct net_device *dev, char __user *useraddr) static int ethtool_get_eee(struct net_device *dev, char __user *useraddr) { - struct ethtool_eee edata; + struct ethtool_eee edata = {0}; int rc; if (!dev->ethtool_ops->get_eee) return -EOPNOTSUPP; - memset(&edata, 0, sizeof(struct ethtool_eee)); edata.cmd = ETHTOOL_GEEE; rc = dev->ethtool_ops->get_eee(dev, &edata); @@ -2109,7 +2104,7 @@ static int ethtool_get_dump_data(struct net_device *dev, { int ret; __u32 len; - struct ethtool_dump dump, tmp; + struct ethtool_dump dump, tmp = {0}; const struct ethtool_ops *ops = dev->ethtool_ops; void *data = NULL; @@ -2119,7 +2114,6 @@ static int ethtool_get_dump_data(struct net_device *dev, if (copy_from_user(&dump, useraddr, sizeof(dump))) return -EFAULT; - memset(&tmp, 0, sizeof(tmp)); tmp.cmd = ETHTOOL_GET_DUMP_FLAG; ret = ops->get_dump_flag(dev, &tmp); if (ret) @@ -2170,11 +2164,10 @@ static int ethtool_get_dump_data(struct net_device *dev, static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr) { int err = 0; - struct ethtool_ts_info info; + struct ethtool_ts_info info = {0}; const struct ethtool_ops *ops = dev->ethtool_ops; struct phy_device *phydev = dev->phydev; - memset(&info, 0, sizeof(info)); info.cmd = ETHTOOL_GET_TS_INFO; if (phydev && phydev->drv && phydev->drv->ts_info) {