]> git.itanic.dy.fi Git - linux-stable/commitdiff
net: transfer rtnl_lock() requirement from ethtool_set_ethtool_phy_ops() to caller
authorVladimir Oltean <vladimir.oltean@nxp.com>
Tue, 1 Aug 2023 14:28:22 +0000 (17:28 +0300)
committerJakub Kicinski <kuba@kernel.org>
Thu, 3 Aug 2023 02:11:06 +0000 (19:11 -0700)
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>
drivers/net/phy/phy_device.c
net/ethtool/common.c

index 61921d4dbb13a82985091accfa943bba021fb71f..98b8ac28e5a1041e8bc8aff766957b6730a1fd98 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/phy_led_triggers.h>
 #include <linux/pse-pd/pse.h>
 #include <linux/property.h>
+#include <linux/rtnetlink.h>
 #include <linux/sfp.h>
 #include <linux/skbuff.h>
 #include <linux/slab.h>
@@ -3451,7 +3452,9 @@ static int __init phy_init(void)
 {
        int rc;
 
+       rtnl_lock();
        ethtool_set_ethtool_phy_ops(&phy_ethtool_phy_ops);
+       rtnl_unlock();
 
        rc = mdio_bus_init();
        if (rc)
@@ -3474,7 +3477,9 @@ static int __init phy_init(void)
 err_mdio_bus:
        mdio_bus_exit();
 err_ethtool_phy_ops:
+       rtnl_lock();
        ethtool_set_ethtool_phy_ops(NULL);
+       rtnl_unlock();
 
        return rc;
 }
@@ -3484,7 +3489,9 @@ static void __exit phy_exit(void)
        phy_driver_unregister(&genphy_c45_driver);
        phy_driver_unregister(&genphy_driver);
        mdio_bus_exit();
+       rtnl_lock();
        ethtool_set_ethtool_phy_ops(NULL);
+       rtnl_unlock();
 }
 
 subsys_initcall(phy_init);
index 5fb19050991e06229466f146956cf84b21cb6140..f5598c5f50de9be3dc29a7ba36facd989740b689 100644 (file)
@@ -665,9 +665,8 @@ const struct ethtool_phy_ops *ethtool_phy_ops;
 
 void ethtool_set_ethtool_phy_ops(const struct ethtool_phy_ops *ops)
 {
-       rtnl_lock();
+       ASSERT_RTNL();
        ethtool_phy_ops = ops;
-       rtnl_unlock();
 }
 EXPORT_SYMBOL_GPL(ethtool_set_ethtool_phy_ops);