net: phy: Validate PHY LED OPs presence before registering
authorChristian Marangi <ansuelsmth@gmail.com>
Tue, 8 Oct 2024 19:47:16 +0000 (21:47 +0200)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 10 Oct 2024 11:55:15 +0000 (13:55 +0200)
Validate PHY LED OPs presence before registering and parsing them.
Defining LED nodes for a PHY driver that actually doesn't supports them
is redundant and useless.

It's also the case with Generic PHY driver used and a DT having LEDs
node for the specific PHY.

Skip it and report the error with debug print enabled.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://patch.msgid.link/20241008194718.9682-1-ansuelsmth@gmail.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/phy/phy_device.c

index 4ccf504a8b2c251387f4f01fe97f7ca008a527dc..bfb28b85392e43d7368edfa8c6b0b57f906d16cf 100644 (file)
@@ -3420,6 +3420,16 @@ static int of_phy_leds(struct phy_device *phydev)
        if (!leds)
                return 0;
 
+       /* Check if the PHY driver have at least an OP to
+        * set the LEDs.
+        */
+       if (!(phydev->drv->led_brightness_set ||
+             phydev->drv->led_blink_set ||
+             phydev->drv->led_hw_control_set)) {
+               phydev_dbg(phydev, "ignoring leds node defined with no PHY driver support\n");
+               goto exit;
+       }
+
        for_each_available_child_of_node_scoped(leds, led) {
                err = of_phy_led(phydev, led);
                if (err) {
@@ -3429,6 +3439,7 @@ static int of_phy_leds(struct phy_device *phydev)
                }
        }
 
+exit:
        of_node_put(leds);
        return 0;
 }