lkml.org 
[lkml]   [2024]   [Feb]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 18/18] net: dsa: microchip: Check return value of of_get_phy_mode()
Hi Daniil,

On Sun, Feb 11, 2024 at 07:08:04AM -0800, Daniil Dulov wrote:
> of_get_phy_mode() may return an error, so add a check.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: edecfa98f602 ("net: dsa: microchip: look for phy-mode in port nodes")
> Signed-off-by: Daniil Dulov <d.dulov@aladdin.ru>
> ---
> drivers/net/dsa/microchip/ksz_common.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
> index e3c338624b95..faffce6ea1e1 100644
> --- a/drivers/net/dsa/microchip/ksz_common.c
> +++ b/drivers/net/dsa/microchip/ksz_common.c
> @@ -434,8 +434,10 @@ int ksz_switch_register(struct ksz_device *dev,
> continue;
> if (port_num >= dev->mib_port_cnt)
> return -EINVAL;
> - of_get_phy_mode(port,
> + ret = of_get_phy_mode(port,
> &dev->ports[port_num].interface);
> + if (ret)
> + return ret;
> }
> dev->synclko_125 = of_property_read_bool(dev->dev->of_node,
> "microchip,synclko-125");
> --
> 2.25.1
>

Not all functions that may return an error, and that error is ignored,
must be fixed.

Here, if of_get_phy_mode() fails, dev->ports[port_num].interface remains
at its default value (0, or PHY_INTERFACE_MODE_NA). It is a valid value
to the rest of the driver at least in some cases (user ports connected
to internal PHYs). And since device tree is ABI, you are proposing to
break something that may have used to work, by making a previously well
treated path now cause an error.

Sorry, NACK even as a matter of principle, do not even bother to resend this
without a more careful analysis.

\
 
 \ /
  Last update: 2024-05-27 15:06    [W:4.711 / U:0.764 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site