netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net: microchip: sparx5: Fix error handling in vcap_show_admin()
@ 2022-11-29  9:43 Dan Carpenter
  2022-11-29 23:13 ` Steen Hegelund
  2022-12-01 11:20 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2022-11-29  9:43 UTC (permalink / raw)
  To: Lars Povlsen, Steen Hegelund
  Cc: Daniel Machon, UNGLinuxDriver, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, kernel-janitors

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>
---
 .../ethernet/microchip/vcap/vcap_api_debugfs.c    | 15 +++++++++++----
 1 file 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 d9c7ca988b76..14fcb3d4ee85 100644
--- a/drivers/net/ethernet/microchip/vcap/vcap_api_debugfs.c
+++ b/drivers/net/ethernet/microchip/vcap/vcap_api_debugfs.c
@@ -639,17 +639,24 @@ 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;
 }
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-01 11:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-29  9:43 [PATCH net-next] net: microchip: sparx5: Fix error handling in vcap_show_admin() Dan Carpenter
2022-11-29 23:13 ` Steen Hegelund
2022-12-01 11:20 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).