[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241218085400.GA779107@debian>
Date: Wed, 18 Dec 2024 09:54:00 +0100
From: Dimitri Fedrau <dima.fedrau@...il.com>
To: Andrew Lunn <andrew@...n.ch>
Cc: Heiner Kallweit <hkallweit1@...il.com>,
Russell King <linux@...linux.org.uk>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH net-next] net: phy: dp83822: Add support for PHY LEDs on
DP83822
Am Tue, Dec 17, 2024 at 06:13:25PM +0100 schrieb Andrew Lunn:
> > +static int dp83822_led_hw_control_set(struct phy_device *phydev, u8 index,
> > + unsigned long rules)
> > +{
> > + int mode;
> > +
> > + mode = dp83822_led_mode(index, rules);
> > + if (mode < 0)
> > + return mode;
> > +
> > + if (index == DP83822_LED_INDEX_LED_0 || index == DP83822_LED_INDEX_COL_GPIO2)
> > + return phy_modify_mmd(phydev, MDIO_MMD_VEND2,
> > + MII_DP83822_MLEDCR, DP83822_MLEDCR_CFG,
> > + FIELD_PREP(DP83822_MLEDCR_CFG, mode));
> > + else if (index == DP83822_LED_INDEX_LED_1_GPIO1)
> > + return phy_modify_mmd(phydev, MDIO_MMD_VEND2,
> > + MII_DP83822_LEDCFG1,
> > + DP83822_LEDCFG1_LED1_CTRL,
> > + FIELD_PREP(DP83822_LEDCFG1_LED1_CTRL,
> > + mode));
> > + else
> > + return phy_modify_mmd(phydev, MDIO_MMD_VEND2,
> > + MII_DP83822_LEDCFG1,
> > + DP83822_LEDCFG1_LED3_CTRL,
> > + FIELD_PREP(DP83822_LEDCFG1_LED3_CTRL,
> > + mode));
>
> index is taken direct from DT. Somebody might have:
>
> leds {
> #address-cells = <1>;
> #size-cells = <0>;
>
> led@42 {
> reg = <42>;
> color = <LED_COLOR_ID_WHITE>;
> function = LED_FUNCTION_LAN;
> default-state = "keep";
> };
> };
>
> so you should not assume if it is not 0, 1 or 2, then it must be
> 3. Please always validate index.
>
By the way. Wouldn't it be helpful adding a u32 max_leds to
struct phy_driver ? Every driver supporting PHY LEDs validates index at the
moment. With max_leds it should be easy to check it in of_phy_leds and
return with an error if index is not valid.
Best regards,
Dimitri
Powered by blists - more mailing lists