diff mbox series

[net-next] net: microchip: sparx5: Fix error handling in vcap_show_admin()

Message ID Y4XUUx9kzurBN+BV@kili (mailing list archive)
State Accepted
Commit 682f560b8a87bfdf174e836640e6ec66a2b3cd9c
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: microchip: sparx5: Fix error handling in vcap_show_admin() | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 2 this patch: 2
netdev/cc_maintainers warning 1 maintainers not CCed: linux-arm-kernel@lists.infradead.org
netdev/build_clang success Errors and warnings before: 5 this patch: 5
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 2 this patch: 2
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 28 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Dan Carpenter Nov. 29, 2022, 9:43 a.m. UTC
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(-)

Comments

Steen Hegelund Nov. 29, 2022, 11:13 p.m. UTC | #1
Hi Dan,

Thanks for the change.  It looks good to me.

On Tue, 2022-11-29 at 12:43 +0300, Dan Carpenter wrote:
> [Some people who received this message don't often get email from
> error27@gmail.com. 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

Reviewed-by: Steen Hegelund <Steen.Hegelund@microchip.com>

BR
Steen
patchwork-bot+netdevbpf@kernel.org Dec. 1, 2022, 11:20 a.m. UTC | #2
Hello:

This patch was applied to netdev/net-next.git (master)
by Paolo Abeni <pabeni@redhat.com>:

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!
diff mbox series

Patch

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;
 }