[PATCH 2/2] net: phy: Make phy_interface_is_rgmii a switch statement

Ramon Fried rfried.dev at gmail.com
Tue Apr 25 21:13:32 CEST 2023


On Thu, Apr 13, 2023 at 9:07 PM Nishanth Menon <nm at ti.com> wrote:
>
> Recent commit 75d28899e3e9 ("net: phy: Synchronize PHY interface modes
> with Linux") reordered the enum definitions. This exposed a problem in
> range checking functions to identify the interface type. Though this
> specific api was'nt impacted (all the RGMII definitions remained within
> range), this experience should be used to never to have to face this
> kind of challenge again.
>
> While it is possible for the phy drivers to practically use the enum's
> directly, drivers such as dp83867, dp83869, marvell, micrel_ksz90x1 etc
> use the same.
>
> Reported-by: Tom Rini <trini at konsulko.com>
> Signed-off-by: Nishanth Menon <nm at ti.com>
> ---
>  include/phy.h | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/include/phy.h b/include/phy.h
> index 1c4dc23bc5ba..812694cf4a81 100644
> --- a/include/phy.h
> +++ b/include/phy.h
> @@ -361,8 +361,16 @@ int get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id);
>   */
>  static inline bool phy_interface_is_rgmii(struct phy_device *phydev)
>  {
> -       return phydev->interface >= PHY_INTERFACE_MODE_RGMII &&
> -               phydev->interface <= PHY_INTERFACE_MODE_RGMII_TXID;
> +       switch (phydev->interface) {
> +       case PHY_INTERFACE_MODE_RGMII:
> +       case PHY_INTERFACE_MODE_RGMII_ID:
> +       case PHY_INTERFACE_MODE_RGMII_RXID:
> +       case PHY_INTERFACE_MODE_RGMII_TXID:
> +               return 1;
> +       default:
> +               fallthrough;
> +       }
> +       return 0;
>  }
>
>  /**
> --
> 2.40.0
>
Reviewed-by: Ramon Fried <rfried.dev at gmail.com>


More information about the U-Boot mailing list