From: Vivien Didelot Date: Fri, 25 Oct 2019 18:48:53 +0000 (-0400) Subject: net: dsa: return directly from dsa_to_port X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=d607525bd912860aad137326a1076d1e9880ddf0;p=linux.git net: dsa: return directly from dsa_to_port Return directly from within the loop as soon as the port is found, otherwise we won't return NULL if the end of the list is reached. Fixes: b96ddf254b09 ("net: dsa: use ports list in dsa_to_port") Signed-off-by: Vivien Didelot Reviewed-by: Andrew Lunn Reviewed-by: Florian Fainelli Signed-off-by: David S. Miller --- diff --git a/include/net/dsa.h b/include/net/dsa.h index d5f6e5ccca38b..9aba326abb643 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -283,13 +283,13 @@ struct dsa_switch { static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p) { struct dsa_switch_tree *dst = ds->dst; - struct dsa_port *dp = NULL; + struct dsa_port *dp; list_for_each_entry(dp, &dst->ports, list) if (dp->ds == ds && dp->index == p) - break; + return dp; - return dp; + return NULL; } static inline bool dsa_is_unused_port(struct dsa_switch *ds, int p)