Skip to content

Commit 6da69b1

Browse files
Xiaomeng Tongkuba-moo
authored andcommitted
net: dsa: bcm_sf2_cfp: fix an incorrect NULL check on list iterator
The bug is here: return rule; The list iterator value 'rule' will *always* be set and non-NULL by list_for_each_entry(), so it is incorrect to assume that the iterator value will be NULL if the list is empty or no element is found. To fix the bug, return 'rule' when found, otherwise return NULL. Fixes: ae7a5af ("net: dsa: bcm_sf2: Keep copy of inserted rules") Reviewed-by: Vladimir Oltean <olteanv@gmail.com> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com> Link: https://lore.kernel.org/r/20220328032431.22538-1-xiam0nd.tong@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent dcf5000 commit 6da69b1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/net/dsa/bcm_sf2_cfp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,14 +567,14 @@ static void bcm_sf2_cfp_slice_ipv6(struct bcm_sf2_priv *priv,
567567
static struct cfp_rule *bcm_sf2_cfp_rule_find(struct bcm_sf2_priv *priv,
568568
int port, u32 location)
569569
{
570-
struct cfp_rule *rule = NULL;
570+
struct cfp_rule *rule;
571571

572572
list_for_each_entry(rule, &priv->cfp.rules_list, next) {
573573
if (rule->port == port && rule->fs.location == location)
574-
break;
574+
return rule;
575575
}
576576

577-
return rule;
577+
return NULL;
578578
}
579579

580580
static int bcm_sf2_cfp_rule_cmp(struct bcm_sf2_priv *priv, int port,

0 commit comments

Comments
 (0)