drivers/net/dsa/mv88e6xxx/chip.c:245 mv88e6xxx_default_mdio_bus() warn: can 'mdio_bus' even be NULL?

From: Dan Carpenter
Date: Sun Dec 03 2023 - 23:46:32 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 815fb87b753055df2d9e50f6cd80eb10235fe3e9
commit: a3c53be55c955b7150cda17874c3fcb4eeb97a89 net: dsa: mv88e6xxx: Support multiple MDIO busses
config: i386-randconfig-141-20231010 (https://download.01.org/0day-ci/archive/20231203/202312030131.Vl3CGtDZ-lkp@xxxxxxxxx/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20231203/202312030131.Vl3CGtDZ-lkp@xxxxxxxxx/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 <lkp@xxxxxxxxx>
| Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
| Closes: https://lore.kernel.org/r/202312030131.Vl3CGtDZ-lkp@xxxxxxxxx/

New smatch warnings:
drivers/net/dsa/mv88e6xxx/chip.c:245 mv88e6xxx_default_mdio_bus() warn: can 'mdio_bus' even be NULL?

vim +/mdio_bus +245 drivers/net/dsa/mv88e6xxx/chip.c

a3c53be55c955b Andrew Lunn 2017-01-24 239 static struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip)
a3c53be55c955b Andrew Lunn 2017-01-24 240 {
a3c53be55c955b Andrew Lunn 2017-01-24 241 struct mv88e6xxx_mdio_bus *mdio_bus;
a3c53be55c955b Andrew Lunn 2017-01-24 242
a3c53be55c955b Andrew Lunn 2017-01-24 243 mdio_bus = list_first_entry(&chip->mdios, struct mv88e6xxx_mdio_bus,
a3c53be55c955b Andrew Lunn 2017-01-24 244 list);
a3c53be55c955b Andrew Lunn 2017-01-24 @245 if (!mdio_bus)

Why is kbuild-bot complaining about 7 year old code? Anyway, the check
is wrong. Was list_first_entry_or_null() intended?

a3c53be55c955b Andrew Lunn 2017-01-24 246 return NULL;
a3c53be55c955b Andrew Lunn 2017-01-24 247
a3c53be55c955b Andrew Lunn 2017-01-24 248 return mdio_bus->bus;
a3c53be55c955b Andrew Lunn 2017-01-24 249 }

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