[PATCH 2/2] net/iucv: Improve error handling in iucv_enable()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
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@xxxxxxxxxxxxxxxxxxxxx>
---
 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






[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux