]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: phy: Don't register LEDs for genphy
authorSean Anderson <sean.anderson@linux.dev>
Mon, 7 Jul 2025 19:58:03 +0000 (15:58 -0400)
committerJakub Kicinski <kuba@kernel.org>
Tue, 15 Jul 2025 00:53:09 +0000 (17:53 -0700)
If a PHY has no driver, the genphy driver is probed/removed directly in
phy_attach/detach. If the PHY's ofnode has an "leds" subnode, then the
LEDs will be (un)registered when probing/removing the genphy driver.
This could occur if the leds are for a non-generic driver that isn't
loaded for whatever reason. Synchronously removing the PHY device in
phy_detach leads to the following deadlock:

rtnl_lock()
ndo_close()
    ...
    phy_detach()
        phy_remove()
            phy_leds_unregister()
                led_classdev_unregister()
                    led_trigger_set()
                        netdev_trigger_deactivate()
                            unregister_netdevice_notifier()
                                rtnl_lock()

There is a corresponding deadlock on the open/register side of things
(and that one is reported by lockdep), but it requires a race while this
one is deterministic.

Generic PHYs do not support LEDs anyway, so don't bother registering
them.

Fixes: 01e5b728e9e4 ("net: phy: Add a binding for PHY LEDs")
Signed-off-by: Sean Anderson <sean.anderson@linux.dev>
Link: https://patch.msgid.link/20250707195803.666097-1-sean.anderson@linux.dev
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/phy/phy_device.c

index 73f9cb2e28442ef01e4b79da7ca1e1ead1f32751..f76ee8489504444ef349fe943297ca21d0ebe5d0 100644 (file)
@@ -3416,7 +3416,8 @@ static int phy_probe(struct device *dev)
        /* Get the LEDs from the device tree, and instantiate standard
         * LEDs for them.
         */
-       if (IS_ENABLED(CONFIG_PHYLIB_LEDS))
+       if (IS_ENABLED(CONFIG_PHYLIB_LEDS) && !phy_driver_is_genphy(phydev) &&
+           !phy_driver_is_genphy_10g(phydev))
                err = of_phy_leds(phydev);
 
 out:
@@ -3433,7 +3434,8 @@ static int phy_remove(struct device *dev)
 
        cancel_delayed_work_sync(&phydev->state_queue);
 
-       if (IS_ENABLED(CONFIG_PHYLIB_LEDS))
+       if (IS_ENABLED(CONFIG_PHYLIB_LEDS) && !phy_driver_is_genphy(phydev) &&
+           !phy_driver_is_genphy_10g(phydev))
                phy_leds_unregister(phydev);
 
        phydev->state = PHY_DOWN;