diff mbox series

tipc: Improve exception handling in tipc_bcast_init()

Message ID b9646b4a-61a2-41fb-8fea-ba63e08996f3@web.de (mailing list archive)
State Rejected
Delegated to: Netdev Maintainers
Headers show
Series tipc: Improve exception handling in tipc_bcast_init() | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1113 this patch: 1113
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 1140 this patch: 1140
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1140 this patch: 1140
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 26 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Markus Elfring Dec. 31, 2023, 11:30 a.m. UTC
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 31 Dec 2023 12:20:06 +0100

The kfree() function was called in two cases by
the tipc_bcast_init() function during error handling
even if the passed variable contained a null pointer.
This issue was detected by using the Coccinelle software.

* Thus return directly after a call of the function “kzalloc” failed
  at the beginning.

* Move one assignment for the variable “tn” closer to the place
  where this pointer is used.

* Delete a redundant kfree() call.

* Omit initialisations (for the local variables)
  which became unnecessary with this refactoring.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 net/tipc/bcast.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

--
2.43.0

Comments

Tung Quang Nguyen Jan. 2, 2024, 12:28 a.m. UTC | #1
>Subject: [PATCH] tipc: Improve exception handling in tipc_bcast_init()
>
>From: Markus Elfring <elfring@users.sourceforge.net>
>Date: Sun, 31 Dec 2023 12:20:06 +0100
>
>The kfree() function was called in two cases by the tipc_bcast_init() function during error handling even if the passed variable
>contained a null pointer.
>This issue was detected by using the Coccinelle software.
kfree() validates the pointer before doing actual memory free. Your patch is not necessary.
diff mbox series

Patch

diff --git a/net/tipc/bcast.c b/net/tipc/bcast.c
index 593846d25214..631aef2dde45 100644
--- a/net/tipc/bcast.c
+++ b/net/tipc/bcast.c
@@ -688,13 +688,15 @@  int tipc_nl_bc_link_set(struct net *net, struct nlattr *attrs[])

 int tipc_bcast_init(struct net *net)
 {
-	struct tipc_net *tn = tipc_net(net);
-	struct tipc_bc_base *bb = NULL;
-	struct tipc_link *l = NULL;
+	struct tipc_net *tn;
+	struct tipc_bc_base *bb;
+	struct tipc_link *l;

 	bb = kzalloc(sizeof(*bb), GFP_KERNEL);
 	if (!bb)
-		goto enomem;
+		return -ENOMEM;
+
+	tn = tipc_net(net);
 	tn->bcbase = bb;
 	spin_lock_init(&tipc_net(net)->bclock);

@@ -715,7 +717,6 @@  int tipc_bcast_init(struct net *net)
 	return 0;
 enomem:
 	kfree(bb);
-	kfree(l);
 	return -ENOMEM;
 }