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>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20080908104530.f9aed821.randy.dunlap@oracle.com>
Date:	Mon, 8 Sep 2008 10:45:30 -0700
From:	Randy Dunlap <randy.dunlap@...cle.com>
To:	lkml <linux-kernel@...r.kernel.org>,
	akpm <akpm@...ux-foundation.org>
Cc:	tpmdd-devel@...ts.sourceforge.net,
	Daniel Marjamäki <danielm77@...ay.se>
Subject: [PATCH bz #11425] tpm: release memory on init failure

From: Randy Dunlap <randy.dunlap@...cle.com>

For kernel bugzilla #11425:
http://bugzilla.kernel.org/show_bug.cgi?id=11425

Release memory on init failure.

Signed-off-by: Randy Dunlap <randy.dunlap@...cle.com>
Reported-by: Daniel Marjamäki <danielm77@...ay.se>
cc: tpmdd-devel@...ts.sourceforge.net
---
 drivers/char/tpm/tpm.c |   19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

--- linux-next-20080905.orig/drivers/char/tpm/tpm.c
+++ linux-next-20080905/drivers/char/tpm/tpm.c
@@ -1183,11 +1183,8 @@ struct tpm_chip *tpm_register_hardware(s
 	chip = kzalloc(sizeof(*chip), GFP_KERNEL);
 	devname = kmalloc(DEVNAME_SIZE, GFP_KERNEL);
 
-	if (chip == NULL || devname == NULL) {
-		kfree(chip);
-		kfree(devname);
-		return NULL;
-	}
+	if (chip == NULL || devname == NULL)
+		goto fail;
 
 	mutex_init(&chip->buffer_mutex);
 	mutex_init(&chip->tpm_mutex);
@@ -1204,8 +1201,7 @@ struct tpm_chip *tpm_register_hardware(s
 
 	if (chip->dev_num >= TPM_NUM_DEVICES) {
 		dev_err(dev, "No available tpm device numbers\n");
-		kfree(chip);
-		return NULL;
+		goto fail;
 	} else if (chip->dev_num == 0)
 		chip->vendor.miscdev.minor = TPM_MINOR;
 	else
@@ -1228,7 +1224,7 @@ struct tpm_chip *tpm_register_hardware(s
 			chip->vendor.miscdev.name,
 			chip->vendor.miscdev.minor);
 		put_device(chip->dev);
-		return NULL;
+		goto fail;
 	}
 
 	spin_lock(&driver_lock);
@@ -1241,12 +1237,17 @@ struct tpm_chip *tpm_register_hardware(s
 		list_del(&chip->list);
 		misc_deregister(&chip->vendor.miscdev);
 		put_device(chip->dev);
-		return NULL;
+		goto fail;
 	}
 
 	chip->bios_dir = tpm_bios_log_setup(devname);
 
 	return chip;
+
+fail:
+	kfree(chip);
+	kfree(devname);
+	return NULL;
 }
 EXPORT_SYMBOL_GPL(tpm_register_hardware);
 


---
~Randy
Linux Plumbers Conference, 17-19 September 2008, Portland, Oregon USA
http://linuxplumbersconf.org/
--
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