Skip to contentSkip to conversation

net: microchip: sparx5: Fix error handling in vcap_show_admin()

PATCH Applied Dan Carpenter 3 participants 3 messages Nov 29, 2022 – Dec 1, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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")
---
 .../ethernet/microchip/vcap/vcap_api_debugfs.c    | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/net/ethernet/microchip/vcap/vcap_api_debugfs.c +11 -4
index d9c7ca988b76..14fcb3d4ee85 100644
@@ -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;
 }
Signature · 1 line
2.35.1
maintainer Reviewed-by on v1 1/1
#1 lore raw

Hi Dan,

Thanks for the change. It looks good to me.

Quoted 9 lines · Dan Carpenter

[Some people who received this message don't often get email from [email protected]. Learn why this is important at
https://aka.ms/LearnAboutSenderIdentification ]

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

If vcap_dup_rule() fails that leads to an error pointer dereference side the ca

BR
Steen

#2 lore raw
In reply to Dan Carpenter
This patch was applied to netdev/net-next.git (master) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (master) by Paolo Abeni <[email protected]>:

Quoted 9 lines · On Tue, 29 Nov 2022 12:43:47 +0300 you wrote:

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.

[...]

Here is the summary with links:
- [net-next] net: microchip: sparx5: Fix error handling in vcap_show_admin()

    https://git.kernel.org/netdev/net-next/c/682f560b8a87

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html