diff mbox series

[net-next] bonding: check slave set command firstly

Message ID 1549030035-22082-1-git-send-email-xiangxia.m.yue@gmail.com
State Changes Requested
Delegated to: David Miller
Headers show
Series [net-next] bonding: check slave set command firstly | expand

Commit Message

Tonghao Zhang Feb. 1, 2019, 2:07 p.m. UTC
From: Tonghao Zhang <xiangxia.m.yue@gmail.com>

This patch is a little improvement. If user use the
command shown as below, we should print the info [1]
instead of [2]. The eth0 exists actually, and it may
confuse user.

$ echo "eth0" > /sys/class/net/bond4/bonding/slaves

[1] "bond4: no command found in slaves file - use +ifname or -ifname"
[2] "write error: No such device"

Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
---
 drivers/net/bonding/bond_options.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Comments

kernel test robot Feb. 2, 2019, 2:38 p.m. UTC | #1
Hi Tonghao,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:    https://github.com/0day-ci/linux/commits/xiangxia-m-yue-gmail-com/bonding-check-slave-set-command-firstly/20190202-215305
config: xtensa-allyesconfig (attached as .config)
compiler: xtensa-linux-gcc (GCC) 8.2.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=8.2.0 make.cross ARCH=xtensa 

Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings

All warnings (new ones prefixed by >>):

   drivers/net/bonding/bond_options.c: In function 'bond_option_slaves_set':
>> drivers/net/bonding/bond_options.c:1403:9: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
     return ret;
            ^~~

vim +/ret +1403 drivers/net/bonding/bond_options.c

0e2e5b66 Nikolay Aleksandrov 2014-01-22  1366  
f3253339 stephen hemminger   2014-03-04  1367  static int bond_option_slaves_set(struct bonding *bond,
28f084cc stephen hemminger   2014-03-06  1368  				  const struct bond_opt_value *newval)
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1369  {
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1370  	char command[IFNAMSIZ + 1] = { 0, };
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1371  	struct net_device *dev;
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1372  	char *ifname;
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1373  	int ret;
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1374  
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1375  	sscanf(newval->string, "%16s", command); /* IFNAMSIZ*/
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1376  	ifname = command + 1;
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1377  	if ((strlen(command) <= 1) ||
c9914772 Tonghao Zhang       2019-02-01  1378  	    (command[0] != '+' && command[0] != '-') ||
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1379  	    !dev_valid_name(ifname))
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1380  		goto err_no_cmd;
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1381  
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1382  	dev = __dev_get_by_name(dev_net(bond->dev), ifname);
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1383  	if (!dev) {
eac306b4 Michael Dilmore     2017-06-26  1384  		netdev_dbg(bond->dev, "interface %s does not exist!\n",
2de390ba Veaceslav Falico    2014-07-15  1385  			   ifname);
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1386  		ret = -ENODEV;
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1387  		goto out;
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1388  	}
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1389  
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1390  	switch (command[0]) {
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1391  	case '+':
eac306b4 Michael Dilmore     2017-06-26  1392  		netdev_dbg(bond->dev, "Adding slave %s\n", dev->name);
33eaf2a6 David Ahern         2017-10-04  1393  		ret = bond_enslave(bond->dev, dev, NULL);
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1394  		break;
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1395  
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1396  	case '-':
eac306b4 Michael Dilmore     2017-06-26  1397  		netdev_dbg(bond->dev, "Removing slave %s\n", dev->name);
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1398  		ret = bond_release(bond->dev, dev);
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1399  		break;
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1400  	}
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1401  
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1402  out:
0e2e5b66 Nikolay Aleksandrov 2014-01-22 @1403  	return ret;
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1404  
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1405  err_no_cmd:
2de390ba Veaceslav Falico    2014-07-15  1406  	netdev_err(bond->dev, "no command found in slaves file - use +ifname or -ifname\n");
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1407  	ret = -EPERM;
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1408  	goto out;
0e2e5b66 Nikolay Aleksandrov 2014-01-22  1409  }
e9f0fb88 Mahesh Bandewar     2014-04-22  1410  

:::::: The code at line 1403 was first introduced by commit
:::::: 0e2e5b66e9de377d69f50a456fdd60462889c64f bonding: convert slaves to use the new option API

:::::: TO: Nikolay Aleksandrov <nikolay@redhat.com>
:::::: CC: David S. Miller <davem@davemloft.net>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
Tonghao Zhang Feb. 3, 2019, 4:59 a.m. UTC | #2
On Sat, Feb 2, 2019 at 10:38 PM kbuild test robot <lkp@intel.com> wrote:
>
> Hi Tonghao,
>
> Thank you for the patch! Perhaps something to improve:
>
> [auto build test WARNING on net-next/master]
>
> url:    https://github.com/0day-ci/linux/commits/xiangxia-m-yue-gmail-com/bonding-check-slave-set-command-firstly/20190202-215305
> config: xtensa-allyesconfig (attached as .config)
> compiler: xtensa-linux-gcc (GCC) 8.2.0
> reproduce:
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # save the attached .config to linux build tree
>         GCC_VERSION=8.2.0 make.cross ARCH=xtensa
>
> Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
> http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings
>
> All warnings (new ones prefixed by >>):
>
>    drivers/net/bonding/bond_options.c: In function 'bond_option_slaves_set':
> >> drivers/net/bonding/bond_options.c:1403:9: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
>      return ret;
>             ^~~
the 'ret' is initialized actually before returning

> vim +/ret +1403 drivers/net/bonding/bond_options.c
>
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1366
> f3253339 stephen hemminger   2014-03-04  1367  static int bond_option_slaves_set(struct bonding *bond,
> 28f084cc stephen hemminger   2014-03-06  1368                             const struct bond_opt_value *newval)
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1369  {
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1370   char command[IFNAMSIZ + 1] = { 0, };
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1371   struct net_device *dev;
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1372   char *ifname;
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1373   int ret;
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1374
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1375   sscanf(newval->string, "%16s", command); /* IFNAMSIZ*/
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1376   ifname = command + 1;
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1377   if ((strlen(command) <= 1) ||
> c9914772 Tonghao Zhang       2019-02-01  1378       (command[0] != '+' && command[0] != '-') ||
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1379       !dev_valid_name(ifname))
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1380           goto err_no_cmd;
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1381
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1382   dev = __dev_get_by_name(dev_net(bond->dev), ifname);
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1383   if (!dev) {
> eac306b4 Michael Dilmore     2017-06-26  1384           netdev_dbg(bond->dev, "interface %s does not exist!\n",
> 2de390ba Veaceslav Falico    2014-07-15  1385                      ifname);
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1386           ret = -ENODEV;
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1387           goto out;
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1388   }
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1389
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1390   switch (command[0]) {
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1391   case '+':
> eac306b4 Michael Dilmore     2017-06-26  1392           netdev_dbg(bond->dev, "Adding slave %s\n", dev->name);
> 33eaf2a6 David Ahern         2017-10-04  1393           ret = bond_enslave(bond->dev, dev, NULL);
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1394           break;
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1395
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1396   case '-':
> eac306b4 Michael Dilmore     2017-06-26  1397           netdev_dbg(bond->dev, "Removing slave %s\n", dev->name);
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1398           ret = bond_release(bond->dev, dev);
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1399           break;
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1400   }
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1401
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1402  out:
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22 @1403   return ret;
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1404
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1405  err_no_cmd:
> 2de390ba Veaceslav Falico    2014-07-15  1406   netdev_err(bond->dev, "no command found in slaves file - use +ifname or -ifname\n");
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1407   ret = -EPERM;
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1408   goto out;
> 0e2e5b66 Nikolay Aleksandrov 2014-01-22  1409  }
> e9f0fb88 Mahesh Bandewar     2014-04-22  1410
>
> :::::: The code at line 1403 was first introduced by commit
> :::::: 0e2e5b66e9de377d69f50a456fdd60462889c64f bonding: convert slaves to use the new option API
>
> :::::: TO: Nikolay Aleksandrov <nikolay@redhat.com>
> :::::: CC: David S. Miller <davem@davemloft.net>
>
> ---
> 0-DAY kernel test infrastructure                Open Source Technology Center
> https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
David Miller Feb. 3, 2019, 7:20 p.m. UTC | #3
From: xiangxia.m.yue@gmail.com
Date: Fri,  1 Feb 2019 06:07:15 -0800

> From: Tonghao Zhang <xiangxia.m.yue@gmail.com>
> 
> This patch is a little improvement. If user use the
> command shown as below, we should print the info [1]
> instead of [2]. The eth0 exists actually, and it may
> confuse user.
> 
> $ echo "eth0" > /sys/class/net/bond4/bonding/slaves
> 
> [1] "bond4: no command found in slaves file - use +ifname or -ifname"
> [2] "write error: No such device"
> 
> Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>

Please fix the compiler warning reported to you.
diff mbox series

Patch

diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
index 4d5d01c..5526229 100644
--- a/drivers/net/bonding/bond_options.c
+++ b/drivers/net/bonding/bond_options.c
@@ -1375,6 +1375,7 @@  static int bond_option_slaves_set(struct bonding *bond,
 	sscanf(newval->string, "%16s", command); /* IFNAMSIZ*/
 	ifname = command + 1;
 	if ((strlen(command) <= 1) ||
+	    (command[0] != '+' && command[0] != '-') ||
 	    !dev_valid_name(ifname))
 		goto err_no_cmd;
 
@@ -1396,9 +1397,6 @@  static int bond_option_slaves_set(struct bonding *bond,
 		netdev_dbg(bond->dev, "Removing slave %s\n", dev->name);
 		ret = bond_release(bond->dev, dev);
 		break;
-
-	default:
-		goto err_no_cmd;
 	}
 
 out: