Skip to content

Commit 70ef7d8

Browse files
vladimirolteankuba-moo
authored andcommitted
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>
1 parent 54e1ed6 commit 70ef7d8

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

drivers/net/phy/phy_device.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <linux/phy_led_triggers.h>
3131
#include <linux/pse-pd/pse.h>
3232
#include <linux/property.h>
33+
#include <linux/rtnetlink.h>
3334
#include <linux/sfp.h>
3435
#include <linux/skbuff.h>
3536
#include <linux/slab.h>
@@ -3451,7 +3452,9 @@ static int __init phy_init(void)
34513452
{
34523453
int rc;
34533454

3455+
rtnl_lock();
34543456
ethtool_set_ethtool_phy_ops(&phy_ethtool_phy_ops);
3457+
rtnl_unlock();
34553458

34563459
rc = mdio_bus_init();
34573460
if (rc)
@@ -3474,7 +3477,9 @@ static int __init phy_init(void)
34743477
err_mdio_bus:
34753478
mdio_bus_exit();
34763479
err_ethtool_phy_ops:
3480+
rtnl_lock();
34773481
ethtool_set_ethtool_phy_ops(NULL);
3482+
rtnl_unlock();
34783483

34793484
return rc;
34803485
}
@@ -3484,7 +3489,9 @@ static void __exit phy_exit(void)
34843489
phy_driver_unregister(&genphy_c45_driver);
34853490
phy_driver_unregister(&genphy_driver);
34863491
mdio_bus_exit();
3492+
rtnl_lock();
34873493
ethtool_set_ethtool_phy_ops(NULL);
3494+
rtnl_unlock();
34883495
}
34893496

34903497
subsys_initcall(phy_init);

net/ethtool/common.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,9 +665,8 @@ const struct ethtool_phy_ops *ethtool_phy_ops;
665665

666666
void ethtool_set_ethtool_phy_ops(const struct ethtool_phy_ops *ops)
667667
{
668-
rtnl_lock();
668+
ASSERT_RTNL();
669669
ethtool_phy_ops = ops;
670-
rtnl_unlock();
671670
}
672671
EXPORT_SYMBOL_GPL(ethtool_set_ethtool_phy_ops);
673672

0 commit comments

Comments
 (0)