From: Markus Elfring <Markus.Elfring@web.de>
To: tipc-discussion@lists.sourceforge.net, netdev@vger.kernel.org,
kernel-janitors@vger.kernel.org,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Jon Maloy <jmaloy@redhat.com>,
Paolo Abeni <pabeni@redhat.com>,
Ying Xue <ying.xue@windriver.com>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] tipc: Improve exception handling in tipc_bcast_init()
Date: Sun, 31 Dec 2023 12:30:34 +0100 [thread overview]
Message-ID: <b9646b4a-61a2-41fb-8fea-ba63e08996f3@web.de> (raw)
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(-)
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;
}
--
2.43.0
next reply other threads:[~2023-12-31 11:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-31 11:30 Markus Elfring [this message]
2024-01-02 0:28 ` Tung Quang Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b9646b4a-61a2-41fb-8fea-ba63e08996f3@web.de \
--to=markus.elfring@web.de \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jmaloy@redhat.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tipc-discussion@lists.sourceforge.net \
--cc=ying.xue@windriver.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®