public inbox for linux-s390@vger.kernel.org
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: linux-s390@vger.kernel.org, netdev@vger.kernel.org,
	kernel-janitors@vger.kernel.org,
	Alexandra Winter <wintera@linux.ibm.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Wenjia Zhang <wenjia@linux.ibm.com>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH 2/2] net/iucv: Improve error handling in iucv_enable()
Date: Mon, 1 Jan 2024 22:00:16 +0100	[thread overview]
Message-ID: <d4b65eeb-0ded-4a04-a58e-496a7609edb3@web.de> (raw)
In-Reply-To: <cde82080-c715-473c-97ac-6ef66bba6d64@web.de>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 1 Jan 2024 21:44:46 +0100

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

* Thus achieve an unlock operation by using the corresponding label.

* Move two error code assignments to other places.

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

diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
index 71ba309e05ee..09e78a57bab8 100644
--- a/net/iucv/iucv.c
+++ b/net/iucv/iucv.c
@@ -543,13 +543,14 @@ static int iucv_enable(void)
 	int cpu, rc;

 	cpus_read_lock();
-	rc = -ENOMEM;
 	alloc_size = iucv_max_pathid * sizeof(struct iucv_path);
 	iucv_path_table = kzalloc(alloc_size, GFP_KERNEL);
-	if (!iucv_path_table)
-		goto out;
+	if (!iucv_path_table) {
+		rc = -ENOMEM;
+		goto unlock;
+	}
+
 	/* Declare per cpu buffers. */
-	rc = -EIO;
 	for_each_online_cpu(cpu)
 		smp_call_function_single(cpu, iucv_declare_cpu, NULL, 1);
 	if (cpumask_empty(&iucv_buffer_cpumask))
@@ -564,6 +565,7 @@ static int iucv_enable(void)
 out:
 	kfree(iucv_path_table);
 	iucv_path_table = NULL;
+	rc = -EIO;
 	goto unlock;
 }

--
2.43.0


      parent reply	other threads:[~2024-01-01 21:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-01 20:56 [PATCH 0/2] net/iucv: Adjustments for iucv_enable() Markus Elfring
2024-01-01 20:58 ` [PATCH 1/2] net/iucv: Improve unlocking in iucv_enable() Markus Elfring
2024-01-02  6:44   ` [EXT] " Suman Ghosh
2024-01-02  7:38     ` Markus Elfring
2024-01-02  8:27       ` [EXT] " Suman Ghosh
2024-01-02  9:53         ` Alexandra Winter
2024-01-02 10:31           ` Markus Elfring
2024-01-01 21:00 ` Markus Elfring [this message]

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=d4b65eeb-0ded-4a04-a58e-496a7609edb3@web.de \
    --to=markus.elfring@web.de \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=wenjia@linux.ibm.com \
    --cc=wintera@linux.ibm.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