net: phy: Validate PHY LED OPs presence before registering
Subsystems (3)
PATCH v2 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 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
@@ -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
Andrew Lunn
maintainerdrivers/net/phy/phy_device.c static int of_phy_leds(struct phy_device *phydev) · line 3429
Quoted 6 lines
drivers/net/phy/phy_device.c +6
-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) {
I think this condition is too strong. All that should be required is led_brightness_set(). The rest can be done in software.
Andrew
---
pw-bot: cr
Quoted 9 lines · Andrew Lunn
drivers/net/phy/phy_device.c static int of_phy_leds(struct phy_device *phydev) · line 3429
Quoted 6 lines
drivers/net/phy/phy_device.c +6
-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) {I think this condition is too strong. All that should be required is
led_brightness_set(). The rest can be done in software.
Some drivers do not offer led_brightness_set().
See for example
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/phy/realtek.c#n1303
Afaik there aren't any drivers which only offer led_blink_set(), that would indeed be a bit weird. But only offering led_hw_control_set() is a (rather sad) reality.
Quoted 10 lines · Andrew Lunn
drivers/net/phy/phy_device.c static int of_phy_leds(struct phy_device *phydev) · line 3429
Quoted 6 lines
drivers/net/phy/phy_device.c +6
-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) {I think this condition is too strong. All that should be required is
led_brightness_set(). The rest can be done in software.
Mhh the idea was really to check if one of the 3 is declared. Ideally to future proof case where some led will only expose led_hw_control_set or only led_blink_set?
Signature · 1 line
Ansuel
Andrew Lunn
maintainerQuoted 12 lines · Christian Marangi
Quoted 10 lines · Andrew Lunn
drivers/net/phy/phy_device.c static int of_phy_leds(struct phy_device *phydev) · line 3429
Quoted 6 lines
drivers/net/phy/phy_device.c +6
-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) {I think this condition is too strong. All that should be required is
led_brightness_set(). The rest can be done in software.
Quoted 3 lines
Mhh the idea was really to check if one of the 3 is declared. Ideally to future proof case where some led will only expose
led_hw_control_setor onlyled_blink_set?
Ah, i read it wrong. Sorry.
Maybe apply De Morgan's laws to make it more readable?
+ if (!(phydev->drv->led_brightness_set ||
+ phydev->drv->led_blink_set ||
+ phydev->drv->led_hw_control_set)) {
However, it is correct as is.
Andrew
Quoted 25 lines · Andrew Lunn
Quoted 12 lines · Christian Marangi
Quoted 10 lines · Andrew Lunn
drivers/net/phy/phy_device.c static int of_phy_leds(struct phy_device *phydev) · line 3429
Quoted 6 lines
drivers/net/phy/phy_device.c +6
-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) {I think this condition is too strong. All that should be required is
led_brightness_set(). The rest can be done in software.Quoted 3 lines
Mhh the idea was really to check if one of the 3 is declared. Ideally to future proof case where some led will only expose
led_hw_control_setor onlyled_blink_set?Ah, i read it wrong. Sorry.
Maybe apply De Morgan's laws to make it more readable?
(quoted diff) +3
-0+ if (!(phydev->drv->led_brightness_set || + phydev->drv->led_blink_set || + phydev->drv->led_hw_control_set)) {
Quoted 2 lines
However, it is correct as is.
Happy to send v3. Np!
Signature · 1 line
Ansuel