as21xxx_led_hw_control_set() looks up the requested rules in as21xxx_led_supported_pattern, but does not check whether a match was found. If the rules are not in the table, val keeps its initial value of 0, so phy_modify_mmd() still gets called, overwriting the current LED configuration with event 0, and the function returns success. Return -EOPNOTSUPP when no matching pattern exists, before touching the hardware, consistent with as21xxx_led_hw_is_supported(). As val is now only used after a successful lookup, drop its redundant zero initialization. Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs") Signed-off-by: Cristian Ciocaltea --- drivers/net/phy/as21xxx.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/as21xxx.c b/drivers/net/phy/as21xxx.c index 90b6f528f76d..1c4a808bf01e 100644 --- a/drivers/net/phy/as21xxx.c +++ b/drivers/net/phy/as21xxx.c @@ -844,7 +844,7 @@ static int as21xxx_led_hw_control_get(struct phy_device *phydev, u8 index, static int as21xxx_led_hw_control_set(struct phy_device *phydev, u8 index, unsigned long rules) { - u16 val = 0; + u16 val; int i; if (index >= AEON_MAX_LEDS) @@ -856,6 +856,9 @@ static int as21xxx_led_hw_control_set(struct phy_device *phydev, u8 index, break; } + if (i == ARRAY_SIZE(as21xxx_led_supported_pattern)) + return -EOPNOTSUPP; + return phy_modify_mmd(phydev, MDIO_MMD_VEND1, VEND1_LED_REG(index), VEND1_LED_REG_A_EVENT, -- 2.56.0