From: Russell King (Oracle) Date: Wed, 23 Oct 2024 13:41:51 +0000 (+0100) Subject: net: phylink: validate sfp_select_interface() returned interface X-Git-Tag: v6.13-rc1~135^2~208^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=41caa7e81b9732a10d523ed6ac57bd67f56494bf;p=thirdparty%2Fkernel%2Flinux.git net: phylink: validate sfp_select_interface() returned interface Validate that the returned interface from sfp_select_interface() is supportable by the MAC/PCS. If it isn't, print an error and return the NA interface type. This is a preparatory step to reorganising how a PHY on a SFP module is handled. Reviewed-by: Maxime Chevallier Tested-by: Maxime Chevallier Signed-off-by: Russell King (Oracle) Link: https://patch.msgid.link/E1t3bcV-000c8B-Vz@rmk-PC.armlinux.org.uk Signed-off-by: Jakub Kicinski --- diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 2eb12bc564526..71dde95daf04e 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -2414,11 +2414,22 @@ static phy_interface_t phylink_sfp_select_interface(struct phylink *pl, phy_interface_t interface; interface = sfp_select_interface(pl->sfp_bus, link_modes); - if (interface == PHY_INTERFACE_MODE_NA) + if (interface == PHY_INTERFACE_MODE_NA) { phylink_err(pl, "selection of interface failed, advertisement %*pb\n", __ETHTOOL_LINK_MODE_MASK_NBITS, link_modes); + return interface; + } + + if (!test_bit(interface, pl->config->supported_interfaces)) { + phylink_err(pl, + "selection of interface failed, SFP selected %s (%u) but MAC supports %*pbl\n", + phy_modes(interface), interface, + (int)PHY_INTERFACE_MODE_MAX, + pl->config->supported_interfaces); + return PHY_INTERFACE_MODE_NA; + } return interface; }