Return error if rule is not found in rule list to avoid Kernel panic.

Signed-off-by: Xiaoliang Yang <xiaoliang.yan...@nxp.com>
---
 drivers/net/ethernet/mscc/ocelot_ace.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mscc/ocelot_ace.c 
b/drivers/net/ethernet/mscc/ocelot_ace.c
index bf2b7a03c832..2ba2859fa2cd 100644
--- a/drivers/net/ethernet/mscc/ocelot_ace.c
+++ b/drivers/net/ethernet/mscc/ocelot_ace.c
@@ -982,9 +982,9 @@ static int ocelot_ace_rule_get_index_id(struct 
ocelot_acl_block *block,
        list_for_each_entry(tmp, &block->rules, list) {
                ++index;
                if (rule->id == tmp->id)
-                       break;
+                       return index;
        }
-       return index;
+       return -ENOENT;
 }
 
 static struct ocelot_ace_rule*
@@ -1197,6 +1197,8 @@ int ocelot_ace_rule_offload_del(struct ocelot *ocelot, 
int block_id,
 
        /* Gets index of the rule */
        index = ocelot_ace_rule_get_index_id(block, rule);
+       if (index < 0)
+               return -ENOENT;
 
        /* Delete rule */
        ocelot_ace_rule_del(ocelot, block, rule);
@@ -1221,6 +1223,9 @@ int ocelot_ace_rule_stats_update(struct ocelot *ocelot, 
int block_id,
        int index;
 
        index = ocelot_ace_rule_get_index_id(block, rule);
+       if (index < 0)
+               return -ENOENT;
+
        vcap_entry_get(ocelot, rule, index, block_id);
 
        /* After we get the result we need to clear the counters */
-- 
2.17.1

Reply via email to