Re: [PATCH] tpm: fix memleak when register hardware fails

From: Rajiv Andrade
Date: Wed May 23 2012 - 11:31:31 EST


On 16/05/12 05:24, Wanlong Gao wrote:
Signed-off-by: Wanlong Gao<gaowanlong@xxxxxxxxxxxxxx>
---
drivers/char/tpm/tpm.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
index ad7c732..c967919 100644
--- a/drivers/char/tpm/tpm.c
+++ b/drivers/char/tpm/tpm.c
@@ -1405,15 +1405,12 @@ struct tpm_chip *tpm_register_hardware(struct device *dev,
"unable to misc_register %s, minor %d\n",
chip->vendor.miscdev.name,
chip->vendor.miscdev.minor);
- put_device(chip->dev);
- return NULL;
+ goto put_device;
}

if (sysfs_create_group(&dev->kobj, chip->vendor.attr_group)) {
misc_deregister(&chip->vendor.miscdev);
- put_device(chip->dev);
-
- return NULL;
+ goto put_device;
}

chip->bios_dir = tpm_bios_log_setup(devname);
@@ -1425,6 +1422,8 @@ struct tpm_chip *tpm_register_hardware(struct device *dev,

return chip;

+put_device:
+ put_device(chip->dev);
out_free:
kfree(chip);
kfree(devname);
Thanks Wanlong, will merge and send James through a git-pull today.

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