Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: phy: constify phydev->drv

Device driver structures are shared between all devices that they
match, and thus nothing should never write to the device driver
structure through the phydev->drv pointer. Let's make this pointer
const to catch code that attempts to do so.

Suggested-by: Christian Marangi <ansuelsmth@gmail.com>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Link: https://lore.kernel.org/r/E1rVxXt-002YqY-9G@rmk-PC.armlinux.org.uk
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Russell King (Oracle) and committed by
Paolo Abeni
0bd199fd 03ba6dc0

+6 -7
+1 -2
drivers/net/phy/phy.c
··· 1290 1290 static irqreturn_t phy_interrupt(int irq, void *phy_dat) 1291 1291 { 1292 1292 struct phy_device *phydev = phy_dat; 1293 - struct phy_driver *drv = phydev->drv; 1294 1293 irqreturn_t ret; 1295 1294 1296 1295 /* Wakeup interrupts may occur during a system sleep transition. ··· 1315 1316 } 1316 1317 1317 1318 mutex_lock(&phydev->lock); 1318 - ret = drv->handle_interrupt(phydev); 1319 + ret = phydev->drv->handle_interrupt(phydev); 1319 1320 mutex_unlock(&phydev->lock); 1320 1321 1321 1322 return ret;
+3 -3
drivers/net/phy/phy_device.c
··· 1413 1413 } 1414 1414 EXPORT_SYMBOL(phy_sfp_probe); 1415 1415 1416 - static bool phy_drv_supports_irq(struct phy_driver *phydrv) 1416 + static bool phy_drv_supports_irq(const struct phy_driver *phydrv) 1417 1417 { 1418 1418 return phydrv->config_intr && phydrv->handle_interrupt; 1419 1419 } ··· 1867 1867 { 1868 1868 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL }; 1869 1869 struct net_device *netdev = phydev->attached_dev; 1870 - struct phy_driver *phydrv = phydev->drv; 1870 + const struct phy_driver *phydrv = phydev->drv; 1871 1871 int ret; 1872 1872 1873 1873 if (phydev->suspended) ··· 1892 1892 1893 1893 int __phy_resume(struct phy_device *phydev) 1894 1894 { 1895 - struct phy_driver *phydrv = phydev->drv; 1895 + const struct phy_driver *phydrv = phydev->drv; 1896 1896 int ret; 1897 1897 1898 1898 lockdep_assert_held(&phydev->lock);
+1 -1
drivers/net/phy/xilinx_gmii2rgmii.c
··· 22 22 23 23 struct gmii2rgmii { 24 24 struct phy_device *phy_dev; 25 - struct phy_driver *phy_drv; 25 + const struct phy_driver *phy_drv; 26 26 struct phy_driver conv_phy_drv; 27 27 struct mdio_device *mdio; 28 28 };
+1 -1
include/linux/phy.h
··· 638 638 639 639 /* Information about the PHY type */ 640 640 /* And management functions */ 641 - struct phy_driver *drv; 641 + const struct phy_driver *drv; 642 642 643 643 struct device_link *devlink; 644 644