Skip to contentSkip to conversation

net: phy: Validate PHY LED OPs presence before registering

PATCH Applied Christian Marangi 3 participants 3 messages Oct 8, 2024 – Oct 10, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 net: phy: Validate PHY LED OPs presence before registering

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.

---
Changes v3:
- Make condition more readable
Changes v2:
- Use phydev_dbg instead of warn

 drivers/net/phy/phy_device.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/net/phy/phy_device.c +11 -0
index 499797646580..e4a1d0e74e47 100644
@@ -3421,6 +3421,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) {
@@ -3430,6 +3440,7 @@ static int of_phy_leds(struct phy_device *phydev)
 		}
 	}
 
+exit:
 	of_node_put(leds);
 	return 0;
 }
Signature · 1 line
2.45.2
maintainer Reviewed-by on v3 1/1
#1 lore raw
Quoted 10 lines · Christian Marangi

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.

Andrew

#2 lore raw
In reply to Christian Marangi
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Quoted 8 lines · On Tue, 8 Oct 2024 21:47:16 +0200 you wrote:

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.

[...]

Here is the summary with links:
- [net-next,v3] net: phy: Validate PHY LED OPs presence before registering

    https://git.kernel.org/netdev/net-next/c/16aef66643a2

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html