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

net: transfer rtnl_lock() requirement from ethtool_set_ethtool_phy_ops() to caller

phy_init() and phy_exit() will have to do more stuff under rtnl_lock()
in a future change. Since rtnl_unlock() -> netdev_run_todo() does a lot
of stuff under the hood, it's a pity to lock and unlock the rtnetlink
mutex twice in a row.

Change the calling convention such that the only caller of
ethtool_set_ethtool_phy_ops(), phy_device.c, provides a context where
the rtnl_mutex is already acquired.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://lore.kernel.org/r/20230801142824.1772134-11-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Vladimir Oltean and committed by
Jakub Kicinski
70ef7d87 54e1ed69

+8 -2
+7
drivers/net/phy/phy_device.c
··· 30 30 #include <linux/phy_led_triggers.h> 31 31 #include <linux/pse-pd/pse.h> 32 32 #include <linux/property.h> 33 + #include <linux/rtnetlink.h> 33 34 #include <linux/sfp.h> 34 35 #include <linux/skbuff.h> 35 36 #include <linux/slab.h> ··· 3452 3451 { 3453 3452 int rc; 3454 3453 3454 + rtnl_lock(); 3455 3455 ethtool_set_ethtool_phy_ops(&phy_ethtool_phy_ops); 3456 + rtnl_unlock(); 3456 3457 3457 3458 rc = mdio_bus_init(); 3458 3459 if (rc) ··· 3477 3474 err_mdio_bus: 3478 3475 mdio_bus_exit(); 3479 3476 err_ethtool_phy_ops: 3477 + rtnl_lock(); 3480 3478 ethtool_set_ethtool_phy_ops(NULL); 3479 + rtnl_unlock(); 3481 3480 3482 3481 return rc; 3483 3482 } ··· 3489 3484 phy_driver_unregister(&genphy_c45_driver); 3490 3485 phy_driver_unregister(&genphy_driver); 3491 3486 mdio_bus_exit(); 3487 + rtnl_lock(); 3492 3488 ethtool_set_ethtool_phy_ops(NULL); 3489 + rtnl_unlock(); 3493 3490 } 3494 3491 3495 3492 subsys_initcall(phy_init);
+1 -2
net/ethtool/common.c
··· 665 665 666 666 void ethtool_set_ethtool_phy_ops(const struct ethtool_phy_ops *ops) 667 667 { 668 - rtnl_lock(); 668 + ASSERT_RTNL(); 669 669 ethtool_phy_ops = ops; 670 - rtnl_unlock(); 671 670 } 672 671 EXPORT_SYMBOL_GPL(ethtool_set_ethtool_phy_ops); 673 672