* [PATCH bz #11425] tpm: release memory on init failure
@ 2008-09-08 17:45 Randy Dunlap
2008-09-09 0:39 ` Andrew Morton
0 siblings, 1 reply; 2+ messages in thread
From: Randy Dunlap @ 2008-09-08 17:45 UTC (permalink / raw)
To: lkml, akpm; +Cc: tpmdd-devel, Daniel Marjamäki
From: Randy Dunlap <randy.dunlap@oracle.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@oracle.com>
Reported-by: Daniel Marjamäki <danielm77@spray.se>
cc: tpmdd-devel@lists.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/
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH bz #11425] tpm: release memory on init failure
2008-09-08 17:45 [PATCH bz #11425] tpm: release memory on init failure Randy Dunlap
@ 2008-09-09 0:39 ` Andrew Morton
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2008-09-09 0:39 UTC (permalink / raw)
To: Randy Dunlap; +Cc: linux-kernel, tpmdd-devel, danielm77
On Mon, 8 Sep 2008 10:45:30 -0700
Randy Dunlap <randy.dunlap@oracle.com> wrote:
> For kernel bugzilla #11425:
> http://bugzilla.kernel.org/show_bug.cgi?id=11425
>
> Release memory on init failure.
Seems I already fixed it:
http://userweb.kernel.org/~akpm/mmotm/broken-out/drivers-char-tpm-tpmc-fix-error-patch-memory-leak.patch
(identical to yours, with a different label name).
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-09-09 0:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-08 17:45 [PATCH bz #11425] tpm: release memory on init failure Randy Dunlap
2008-09-09 0:39 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome