lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <1278997358.4112.2.camel@mola>
Date:	Tue, 13 Jul 2010 13:02:38 +0800
From:	Axel Lin <axel.lin@...il.com>
To:	linux-kernel <linux-kernel@...r.kernel.org>
Cc:	Stephen Hemminger <shemminger@...tta.com>,
	Jens Axboe <jens.axboe@...cle.com>,
	David Teigland <teigland@...hat.com>,
	Pekka Enberg <penberg@...helsinki.fi>,
	"Hans J. Koch" <hjk@...utronix.de>,
	Andrew Morton <akpm@...ux-foundation.org>
Subject: [PATCH v3] edd: fix possible memory leak in edd_init() error path

This version simply fix the coding style in v2. ( warnning by checkpatch.pl )

>>From 7400dff50f7a6036839009d6990fd5c11f0654db Mon Sep 17 00:00:00 2001
From: Axel Lin <axel.lin@...il.com>
Date: Tue, 13 Jul 2010 12:56:19 +0800
Subject: [PATCH v3] edd: fix possible memory leak in edd_init() error path

The error may happen at any iteration of the for loop,
this patch properly unregisters already registed edd_devices in error path.

Signed-off-by: Axel Lin <axel.lin@...il.com>
---
 drivers/firmware/edd.c |   20 +++++++++++++-------
 1 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c
index 110e24e..f287fe7 100644
--- a/drivers/firmware/edd.c
+++ b/drivers/firmware/edd.c
@@ -744,7 +744,7 @@ static inline int edd_num_devices(void)
 static int __init
 edd_init(void)
 {
-	unsigned int i;
+	int i;
 	int rc=0;
 	struct edd_device *edev;
 
@@ -760,21 +760,27 @@ edd_init(void)
 	if (!edd_kset)
 		return -ENOMEM;
 
-	for (i = 0; i < edd_num_devices() && !rc; i++) {
+	for (i = 0; i < edd_num_devices(); i++) {
 		edev = kzalloc(sizeof (*edev), GFP_KERNEL);
-		if (!edev)
-			return -ENOMEM;
+		if (!edev) {
+			rc = -ENOMEM;
+			goto out;
+		}
 
 		rc = edd_device_register(edev, i);
 		if (rc) {
 			kfree(edev);
-			break;
+			goto out;
 		}
 		edd_devices[i] = edev;
 	}
 
-	if (rc)
-		kset_unregister(edd_kset);
+	return 0;
+
+out:
+	while (--i >= 0)
+		edd_device_unregister(edd_devices[i]);
+	kset_unregister(edd_kset);
 	return rc;
 }
 
-- 
1.5.4.3



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ