Skip to content

Commit 682f560

Browse files
error27Paolo Abeni
authored andcommitted
net: microchip: sparx5: Fix error handling in vcap_show_admin()
If vcap_dup_rule() fails that leads to an error pointer dereference side the call to vcap_free_rule(). Also it only returns an error if the very last call to vcap_read_rule() fails and it returns success for other errors. I've changed it to just stop printing after the first error and return an error code. Fixes: 3a79215 ("net: microchip: sparx5: Add VCAP rule debugFS support for the VCAP API") Signed-off-by: Dan Carpenter <[email protected]> Reviewed-by: Steen Hegelund <[email protected]> Link: https://lore.kernel.org/r/Y4XUUx9kzurBN+BV@kili Signed-off-by: Paolo Abeni <[email protected]>
1 parent e5214f3 commit 682f560

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

drivers/net/ethernet/microchip/vcap/vcap_api_debugfs.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,17 +639,24 @@ static int vcap_show_admin(struct vcap_control *vctrl,
639639
mutex_lock(&admin->lock);
640640
list_for_each_entry(elem, &admin->rules, list) {
641641
ri = vcap_dup_rule(elem);
642-
if (IS_ERR(ri))
643-
goto free_rule;
642+
if (IS_ERR(ri)) {
643+
ret = PTR_ERR(ri);
644+
goto err_unlock;
645+
}
644646
/* Read data from VCAP */
645647
ret = vcap_read_rule(ri);
646648
if (ret)
647-
goto free_rule;
649+
goto err_free_rule;
648650
out->prf(out->dst, "\n");
649651
vcap_show_admin_rule(vctrl, admin, out, ri);
650-
free_rule:
651652
vcap_free_rule((struct vcap_rule *)ri);
652653
}
654+
mutex_unlock(&admin->lock);
655+
return 0;
656+
657+
err_free_rule:
658+
vcap_free_rule((struct vcap_rule *)ri);
659+
err_unlock:
653660
mutex_unlock(&admin->lock);
654661
return ret;
655662
}

0 commit comments

Comments
 (0)