Re: [PATCH v2] net: phy: Fix return value when !CONFIG_PHYLIB

From: 胡海
Date: Sun Apr 13 2025 - 22:41:46 EST


Russell King (Oracle) <linux@xxxxxxxxxxxxxxx> 于2025年4月13日周日 22:13写道:
>
> On Sun, Apr 13, 2025 at 09:37:09PM +0800, hhtracer@xxxxxxxxx wrote:
> > Many call sites of get_phy_device() and fwnode_get_phy_node(), such as
> > sfp_sm_probe_phy(), phylink_fwnode_phy_connect(), etc., rely on IS_ERR()
> > to check for errors in the returned pointer.
> >
> > Furthermore, the implementations of get_phy_device() and
> > fwnode_get_phy_node() themselves use ERR_PTR() to return error codes.
> >
> > Therefore, when CONFIG_PHYLIB is disabled, returning NULL is incorrect,
> > as this would bypass IS_ERR() checks and may lead to NULL pointer
> > dereference.
> >
> > Returning ERR_PTR(-ENXIO) is the correct and consistent way to indicate
> > that PHY support is not available, and it avoids such issues.
>
> I wonder whether it's crossed one's mind that returning NULL may be
> intentional to avoid erroring out at the callsites, and returning
> an error may cause runtime failures.
>
> You need to do way more investigation before posting a patch like this:
>
> - Analyse each call site.
> - Determine whether that call site can exist if PHYLIB is not built.
> - Determine whether returning an error in that case instead of NULL
> may be detrimental, or at the very least list the call sites that
> would be affected by the change.

Yes, when PHYLIB is not built, the relevant call sites are not
compiled in, so they won't exist.

Thanks for the clarification!

>
> Thanks.
>
> --
> RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
> FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!