net: dsa: bcm_sf2: Fix overflow checks
[platform/kernel/linux-rpi.git] / drivers / net / dsa / bcm_sf2_cfp.c
index 471837c..e15d18b 100644 (file)
@@ -882,17 +882,14 @@ static int bcm_sf2_cfp_rule_set(struct dsa_switch *ds, int port,
             fs->m_ext.data[1]))
                return -EINVAL;
 
-       if (fs->location != RX_CLS_LOC_ANY && fs->location >= CFP_NUM_RULES)
+       if (fs->location != RX_CLS_LOC_ANY &&
+           fs->location > bcm_sf2_cfp_rule_size(priv))
                return -EINVAL;
 
        if (fs->location != RX_CLS_LOC_ANY &&
            test_bit(fs->location, priv->cfp.used))
                return -EBUSY;
 
-       if (fs->location != RX_CLS_LOC_ANY &&
-           fs->location > bcm_sf2_cfp_rule_size(priv))
-               return -EINVAL;
-
        ret = bcm_sf2_cfp_rule_cmp(priv, port, fs);
        if (ret == 0)
                return -EEXIST;
@@ -973,7 +970,7 @@ static int bcm_sf2_cfp_rule_del(struct bcm_sf2_priv *priv, int port, u32 loc)
        struct cfp_rule *rule;
        int ret;
 
-       if (loc >= CFP_NUM_RULES)
+       if (loc > bcm_sf2_cfp_rule_size(priv))
                return -EINVAL;
 
        /* Refuse deleting unused rules, and those that are not unique since