The LED indexes are zero-based, so valid indexes are strictly less than the number of LEDs, AEON_MAX_LEDS. However, the LED ops only reject indexes greater than AEON_MAX_LEDS, which wrongly accepts an index equal to AEON_MAX_LEDS, one past the last valid LED. Such an index makes VEND1_LED_REG() compute an address outside the LED register block. A bogus LED node in the device tree can then cause reads and writes of an unrelated vendor register. Reject indexes greater than or equal to AEON_MAX_LEDS so that only valid LED indexes are accepted. Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs") Signed-off-by: Cristian Ciocaltea --- drivers/net/phy/as21xxx.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/net/phy/as21xxx.c b/drivers/net/phy/as21xxx.c index 5fb06cd765cf..5b38c641329a 100644 --- a/drivers/net/phy/as21xxx.c +++ b/drivers/net/phy/as21xxx.c @@ -781,7 +781,7 @@ static int as21xxx_led_brightness_set(struct phy_device *phydev, { u16 val = VEND1_LED_REG_A_EVENT_OFF; - if (index > AEON_MAX_LEDS) + if (index >= AEON_MAX_LEDS) return -EINVAL; if (value) @@ -798,7 +798,7 @@ static int as21xxx_led_hw_is_supported(struct phy_device *phydev, u8 index, { int i; - if (index > AEON_MAX_LEDS) + if (index >= AEON_MAX_LEDS) return -EINVAL; for (i = 0; i < ARRAY_SIZE(as21xxx_led_supported_pattern); i++) @@ -813,7 +813,7 @@ static int as21xxx_led_hw_control_get(struct phy_device *phydev, u8 index, { int i, val; - if (index > AEON_MAX_LEDS) + if (index >= AEON_MAX_LEDS) return -EINVAL; val = phy_read_mmd(phydev, MDIO_MMD_VEND1, VEND1_LED_REG(index)); @@ -837,7 +837,7 @@ static int as21xxx_led_hw_control_set(struct phy_device *phydev, u8 index, u16 val = 0; int i; - if (index > AEON_MAX_LEDS) + if (index >= AEON_MAX_LEDS) return -EINVAL; for (i = 0; i < ARRAY_SIZE(as21xxx_led_supported_pattern); i++) @@ -859,7 +859,7 @@ static int as21xxx_led_polarity_set(struct phy_device *phydev, int index, u16 mask, val = 0; u32 mode; - if (index > AEON_MAX_LEDS) + if (index >= AEON_MAX_LEDS) return -EINVAL; for_each_set_bit(mode, &modes, __PHY_LED_MODES_NUM) { -- 2.56.0