Skip to contentSkip to conversation

drivers/net/phy/phy_device.c:1836 phy_detach() error: we previously assumed 'dev' could be null (see line 1815)

PATCH New Dan Carpenter 1 participant 1 message Feb 5, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 21/51 drivers/net/phy/phy_device.c:1836 phy_detach() error: we previously assumed 'dev' could be null (see line 1815)

tree:   https://github.com/tobetter/linux odroid-6.6.y
head:   0ea9759612aba09cc99b50301b281417f70e847c
commit: 10a25be4b77c699179ad1d36f7c67491c812c34e [21/51] ODROID-COMMON: phy/realtek: add Wake-on-Lan to Realtek PHY
config: i386-randconfig-141-20240203 (https://download.01.org/0day-ci/archive/20240204/[email protected]/config)
compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)

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 protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

smatch warnings:
drivers/net/phy/phy_device.c:1836 phy_detach() error: we previously assumed 'dev' could be null (see line 1815) drivers/net/phy/phy_device.c:1848 phy_detach() warn: variable dereferenced before check 'dev' (see line 1836)

vim +/dev +1836 drivers/net/phy/phy_device.c

e13934563db047 Andy Fleming       2005-08-24  1795  void phy_detach(struct phy_device *phydev)
e13934563db047 Andy Fleming       2005-08-24  1796  {
ec988ad78ed6d1 Florian Fainelli   2016-12-06  1797  	struct net_device *dev = phydev->attached_dev;
2db2d9d1ac3722 Ioana Ciornei      2019-05-28  1798  	struct module *ndev_owner = NULL;
3e3aaf64941698 Russell King       2015-09-24  1799  	struct mii_bus *bus;
b3565f278a9bab Ezequiel Garcia    2014-07-23  1800  
bc66fa87d4fda9 Xiaolei Wang       2022-11-30  1801  	if (phydev->devlink)
bc66fa87d4fda9 Xiaolei Wang       2022-11-30  1802  		device_link_del(phydev->devlink);
bc66fa87d4fda9 Xiaolei Wang       2022-11-30  1803  
a3995460491d45 Florian Fainelli   2017-05-27  1804  	if (phydev->sysfs_links) {
2db2d9d1ac3722 Ioana Ciornei      2019-05-28  1805  		if (dev)
                                                                    ^^^

Check for NULL

5568363f0cb358 Florian Fainelli   2017-05-25  1806  			sysfs_remove_link(&dev->dev.kobj, "phydev");
5568363f0cb358 Florian Fainelli   2017-05-25  1807  		sysfs_remove_link(&phydev->mdio.dev.kobj, "attached_dev");
a3995460491d45 Florian Fainelli   2017-05-27  1808  	}
c920f745f45d46 Ioana Ciornei      2019-05-28  1809  
c920f745f45d46 Ioana Ciornei      2019-05-28  1810  	if (!phydev->attached_dev)
c920f745f45d46 Ioana Ciornei      2019-05-28  1811  		sysfs_remove_file(&phydev->mdio.dev.kobj,
c920f745f45d46 Ioana Ciornei      2019-05-28  1812  				  &dev_attr_phy_standalone.attr);
c920f745f45d46 Ioana Ciornei      2019-05-28  1813  
93f41e67dc8ff0 Heiner Kallweit    2018-09-24  1814  	phy_suspend(phydev);
2db2d9d1ac3722 Ioana Ciornei      2019-05-28 @1815  	if (dev) {
                                                            ^^^

Checked here again

c1f19b51d1d87f Richard Cochran    2010-07-17  1816  		phydev->attached_dev->phydev = NULL;
e13934563db047 Andy Fleming       2005-08-24  1817  		phydev->attached_dev = NULL;
2db2d9d1ac3722 Ioana Ciornei      2019-05-28  1818  	}
9525ae83959b60 Russell King       2017-07-25  1819  	phydev->phylink = NULL;
e13934563db047 Andy Fleming       2005-08-24  1820  
d98ce1f083cca8 Daniel Golle       2023-12-12  1821  	if (!phydev->is_on_sfp_module)
0075bd692dca03 Geert Uytterhoeven 2016-11-28  1822  		phy_led_triggers_unregister(phydev);
0075bd692dca03 Geert Uytterhoeven 2016-11-28  1823  
c2b727df7caa33 Florian Fainelli   2020-09-16  1824  	if (phydev->mdio.dev.driver)
6d9f66ac7fec2a Florian Fainelli   2017-02-08  1825  		module_put(phydev->mdio.dev.driver->owner);
6d9f66ac7fec2a Florian Fainelli   2017-02-08  1826  
e13934563db047 Andy Fleming       2005-08-24  1827  	/* If the device had no specific driver before (i.e. - it
e13934563db047 Andy Fleming       2005-08-24  1828  	 * was using the generic driver), we unbind the device
e13934563db047 Andy Fleming       2005-08-24  1829  	 * from the generic driver so that there's a chance a
2f53e9047e79b6 Sergei Shtylyov    2014-01-05  1830  	 * real driver could be loaded
2f53e9047e79b6 Sergei Shtylyov    2014-01-05  1831  	 */
5db5ea995fc2fa Florian Fainelli   2019-01-15  1832  	if (phy_driver_is_genphy(phydev) ||
5db5ea995fc2fa Florian Fainelli   2019-01-15  1833  	    phy_driver_is_genphy_10g(phydev))
e5a03bfd873c29 Andrew Lunn        2016-01-06  1834  		device_release_driver(&phydev->mdio.dev);
3e3aaf64941698 Russell King       2015-09-24  1835  
10a25be4b77c69 Dongjin Kim        2021-11-17 @1836  	if (!dev->wol_enabled) {
                                                             ^^^^^

Dereferenced without checking.

cbda1b16687580 Marek Behún        2022-01-19  1837  		/* Assert the reset signal */
cbda1b16687580 Marek Behún        2022-01-19  1838  		phy_device_reset(phydev, 1);
10a25be4b77c69 Dongjin Kim        2021-11-17  1839  	}
cbda1b16687580 Marek Behún        2022-01-19  1840  
7322967bc1bd97 Russell King       2015-09-24  1841  	/*
7322967bc1bd97 Russell King       2015-09-24  1842  	 * The phydev might go away on the put_device() below, so avoid
7322967bc1bd97 Russell King       2015-09-24  1843  	 * a use-after-free bug by reading the underlying bus first.
7322967bc1bd97 Russell King       2015-09-24  1844  	 */
e5a03bfd873c29 Andrew Lunn        2016-01-06  1845  	bus = phydev->mdio.bus;
3e3aaf64941698 Russell King       2015-09-24  1846  
e5a03bfd873c29 Andrew Lunn        2016-01-06  1847  	put_device(&phydev->mdio.dev);
2db2d9d1ac3722 Ioana Ciornei      2019-05-28 @1848  	if (dev)
                                                            ^^^

Checked here

2db2d9d1ac3722 Ioana Ciornei      2019-05-28  1849  		ndev_owner = dev->dev.parent->driver->owner;
ec988ad78ed6d1 Florian Fainelli   2016-12-06  1850  	if (ndev_owner != bus->owner)
3e3aaf64941698 Russell King       2015-09-24  1851  		module_put(bus->owner);
e13934563db047 Andy Fleming       2005-08-24  1852  }
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki