lkml.org 
[lkml]   [2008]   [Sep]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH bz #11425] tpm: release memory on init failure
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/
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2008-09-08 19:49    [W:0.033 / U:3.496 seconds]
©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site