2022-06-21 14:36:53

by Yann Sionneau

[permalink] [raw]
Subject: [PATCH] net: phylink: check for pcs_ops being NULL

Out of tree drivers that have not been updated
after 001f4261fe4d ("net: phylink: use legacy_pre_march2020") would not set the
legacy_pre_march2020 boolean which if not initialized will default to false.
Such drivers will most likely still be using the legacy interface and will
not have pcs_ops.

Check for pcs_ops being NULL even if driver does not advertise itself
as "pre march 2020 legacy". This commit adds a simple check instead of
dereferencing a NULL pointer and prints an error message to indicate
that the driver needs to be updated.

Signed-off-by: Yann Sionneau <[email protected]>
---
drivers/net/phy/phylink.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 06943889d747..94abf418afb1 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -874,6 +874,14 @@ static int phylink_change_inband_advert(struct phylink *pl)
return 0;
}

+ if (unlikely(!pl->pcs_ops)) {
+ phylink_err(pl, "%s: Error, net driver needs to either be "
+ "updated to use pcs_ops or actually advertise it "
+ "has legacy interface by setting "
+ "legacy_pre_march2020 boolean", __func__);
+ return -EINVAL;
+ }
+
phylink_dbg(pl, "%s: mode=%s/%s adv=%*pb pause=%02x\n", __func__,
phylink_an_mode_str(pl->cur_link_an_mode),
phy_modes(pl->link_config.interface),
--
2.17.1


2022-06-21 16:38:04

by Russell King (Oracle)

[permalink] [raw]
Subject: Re: [PATCH] net: phylink: check for pcs_ops being NULL

On Tue, Jun 21, 2022 at 03:49:17PM +0200, Yann Sionneau wrote:
> Out of tree drivers that have not been updated
> after 001f4261fe4d ("net: phylink: use legacy_pre_march2020") would not set the
> legacy_pre_march2020 boolean which if not initialized will default to false.
> Such drivers will most likely still be using the legacy interface and will
> not have pcs_ops.

... which means they're broken. The answer is not to patch phylink like
this, because even with this, it's likely that they are still broken.

They need to set legacy_pre_march2020.

Note that the legacy stuff will be going away - some of it, such as the
mac_pcs_an_restart() method will be going away, maybe in the next merge
window.

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