Subject: Re: [PATCH net-next v4 2/5] netdevsim: allow two netdevsim ports to be connected

From: kernel test robot <[email-masked]>
Date: Wed, 20 Dec 2023 20:58:42 +0800

Hi David,

kernel test robot noticed the following build warnings:

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

url:    https://github.com/intel-lab-lkp/linux/commits/David-Wei/netdevsim-maintain-a-list-of-probed-netdevsims/20231220-095238
base:   net-next/main
patch link:    https://lore.kernel.org/r/20231220014747.1508581-3-dw%40davidwei.uk
patch subject: [PATCH net-next v4 2/5] netdevsim: allow two netdevsim ports to be connected
config: arm64-allyesconfig (https://download.01.org/0day-ci/archive/20231220/[email-masked]/config)
compiler: clang version 18.0.0git (https://github.com/llvm/llvm-project 10056c821a56a19cef732129e4e0c5883ae1ee49)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231220/[email-masked]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email-masked]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email-masked]/

All warnings (new ones prefixed by >>):

>> drivers/net/netdevsim/dev.c:431:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     431 |         if (!peer)
         |             ^~~~~
   drivers/net/netdevsim/dev.c:443:9: note: uninitialized use occurs here
     443 |         return ret;
         |                ^~~
   drivers/net/netdevsim/dev.c:431:2: note: remove the 'if' if its condition is always false
     431 |         if (!peer)
         |         ^~~~~~~~~~
     432 |                 goto out;
         |                 ~~~~~~~~
   drivers/net/netdevsim/dev.c:425:13: note: initialize the variable 'ret' to silence this warning
     425 |         ssize_t ret;
         |                    ^
         |                     = 0
   1 warning generated.

vim +431 drivers/net/netdevsim/dev.c

   417	
   418	static ssize_t nsim_dev_peer_read(struct file *file, char __user *data,
   419					  size_t count, loff_t *ppos)
   420	{
   421		struct nsim_dev_port *nsim_dev_port;
   422		struct netdevsim *peer;
   423		unsigned int id, port;
   424		char buf[23];
   425		ssize_t ret;
   426	
   427		mutex_lock(&nsim_dev_list_lock);
   428		rtnl_lock();
   429		nsim_dev_port = file->private_data;
   430		peer = rtnl_dereference(nsim_dev_port->ns->peer);
 > 431		if (!peer)
   432			goto out;
   433	
   434		id = peer->nsim_bus_dev->dev.id;
   435		port = peer->nsim_dev_port->port_index;
   436		ret = scnprintf(buf, sizeof(buf), "%u %u\n", id, port);
   437		ret = simple_read_from_buffer(data, count, ppos, buf, ret);
   438	
   439	out:
   440		rtnl_unlock();
   441		mutex_unlock(&nsim_dev_list_lock);
   442	
   443		return ret;
   444	}
   445	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki