diff options
author | Dan Carpenter <error27@gmail.com> | 2022-11-29 12:43:47 +0300 |
---|---|---|
committer | Paolo Abeni <pabeni@redhat.com> | 2022-12-01 12:12:23 +0100 |
commit | 682f560b8a87bfdf174e836640e6ec66a2b3cd9c (patch) | |
tree | b4286c716fd01ff5746111e75d7bc714d6480a77 | |
parent | e5214f363dabca240446272dac54d404501ad5e5 (diff) | |
download | linux-682f560b8a87bfdf174e836640e6ec66a2b3cd9c.tar.bz2 |
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: 3a7921560d2f ("net: microchip: sparx5: Add VCAP rule debugFS support for the VCAP API")
Signed-off-by: Dan Carpenter <error27@gmail.com>
Reviewed-by: Steen Hegelund <Steen.Hegelund@microchip.com>
Link: https://lore.kernel.org/r/Y4XUUx9kzurBN+BV@kili
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
-rw-r--r-- | drivers/net/ethernet/microchip/vcap/vcap_api_debugfs.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api_debugfs.c b/drivers/net/ethernet/microchip/vcap/vcap_api_debugfs.c index 5df00e940333..3b8d165dc832 100644 --- a/drivers/net/ethernet/microchip/vcap/vcap_api_debugfs.c +++ b/drivers/net/ethernet/microchip/vcap/vcap_api_debugfs.c @@ -639,18 +639,25 @@ static int vcap_show_admin(struct vcap_control *vctrl, mutex_lock(&admin->lock); list_for_each_entry(elem, &admin->rules, list) { ri = vcap_dup_rule(elem); - if (IS_ERR(ri)) - goto free_rule; + if (IS_ERR(ri)) { + ret = PTR_ERR(ri); + goto err_unlock; + } /* Read data from VCAP */ ret = vcap_read_rule(ri); if (ret) - goto free_rule; + goto err_free_rule; out->prf(out->dst, "\n"); vcap_show_admin_rule(vctrl, admin, out, ri); -free_rule: vcap_free_rule((struct vcap_rule *)ri); } mutex_unlock(&admin->lock); + return 0; + +err_free_rule: + vcap_free_rule((struct vcap_rule *)ri); +err_unlock: + mutex_unlock(&admin->lock); return ret; } |