[net-next,v2,4/4] net: pcs: xpcs: Explicitly return error on caps validation

Message ID 20240222175843.26919-5-fancer.lancer@gmail.com
State New
Headers
Series [net-next,v2,1/4] net: pcs: xpcs: Drop sentinel entry from 2500basex ifaces list |

Commit Message

Serge Semin Feb. 22, 2024, 5:58 p.m. UTC
  If an unsupported interface is passed to the PCS validation callback there
is no need in further link-modes calculations since the resultant array
will be initialized with zeros which will be perceived by the phylink
subsystem as error anyway (see phylink_validate_mac_and_pcs()). Instead
let's explicitly return the -EINVAL error to inform the caller about the
unsupported interface as it's done in the rest of the pcs_validate
callbacks.

Signed-off-by: Serge Semin <fancer.lancer@gmail.com>
---
 drivers/net/pcs/pcs-xpcs.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
  

Comments

Maxime Chevallier Feb. 23, 2024, 9:56 a.m. UTC | #1
Hello Serge,

On Thu, 22 Feb 2024 20:58:23 +0300
Serge Semin <fancer.lancer@gmail.com> wrote:

> If an unsupported interface is passed to the PCS validation callback there
> is no need in further link-modes calculations since the resultant array
> will be initialized with zeros which will be perceived by the phylink
> subsystem as error anyway (see phylink_validate_mac_and_pcs()). Instead
> let's explicitly return the -EINVAL error to inform the caller about the
> unsupported interface as it's done in the rest of the pcs_validate
> callbacks.
> 
> Signed-off-by: Serge Semin <fancer.lancer@gmail.com>

This looks good to me,

Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
  

Patch

diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c
index 92c47da61db4..46afeb5510c0 100644
--- a/drivers/net/pcs/pcs-xpcs.c
+++ b/drivers/net/pcs/pcs-xpcs.c
@@ -613,14 +613,15 @@  static int xpcs_validate(struct phylink_pcs *pcs, unsigned long *supported,
 
 	xpcs = phylink_pcs_to_xpcs(pcs);
 	compat = xpcs_find_compat(xpcs->id, state->interface);
+	if (!compat)
+		return -EINVAL;
 
 	/* Populate the supported link modes for this PHY interface type.
 	 * FIXME: what about the port modes and autoneg bit? This masks
 	 * all those away.
 	 */
-	if (compat)
-		for (i = 0; compat->supported[i] != __ETHTOOL_LINK_MODE_MASK_NBITS; i++)
-			set_bit(compat->supported[i], xpcs_supported);
+	for (i = 0; compat->supported[i] != __ETHTOOL_LINK_MODE_MASK_NBITS; i++)
+		set_bit(compat->supported[i], xpcs_supported);
 
 	linkmode_and(supported, supported, xpcs_supported);