diff options
author | Andrew Morton <akpm@linux-foundation.org> | 2008-10-15 22:04:37 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-10-16 11:21:49 -0700 |
commit | dd78c9439fc1e031835bccb934d27b978c72c536 (patch) | |
tree | 003eb90233367defab682643dc1cc143a302dc68 /drivers/char | |
parent | 63a10dfdda0e2262f5b61b54b6d9b1747a87ff54 (diff) |
drivers/char/tpm/tpm.c: fix error-path memory leak
tpm_register_hardware() leaks devname on an error path.
Addresses http://bugzilla.kernel.org/show_bug.cgi?id=11425
Reported-by: Daniel Marjamki <danielm77@spray.se>
Cc: Debora Velarde <debora@linux.vnet.ibm.com>
Cc: Rajiv Andrade <srajiv@linux.vnet.ibm.com>
Cc: Marcel Selhorst <tpm@selhorst.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/char')
-rw-r--r-- | drivers/char/tpm/tpm.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c index aa899cec6b3..e70d13defde 100644 --- a/drivers/char/tpm/tpm.c +++ b/drivers/char/tpm/tpm.c @@ -1187,11 +1187,8 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, 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 out_free; mutex_init(&chip->buffer_mutex); mutex_init(&chip->tpm_mutex); @@ -1208,8 +1205,7 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, if (chip->dev_num >= TPM_NUM_DEVICES) { dev_err(dev, "No available tpm device numbers\n"); - kfree(chip); - return NULL; + goto out_free; } else if (chip->dev_num == 0) chip->vendor.miscdev.minor = TPM_MINOR; else @@ -1250,6 +1246,11 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, spin_unlock(&driver_lock); return chip; + +out_free: + kfree(chip); + kfree(devname); + return NULL; } EXPORT_SYMBOL_GPL(tpm_register_hardware); |