aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Morton <akpm@linux-foundation.org>2008-10-16 01:04:37 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-10-16 14:21:49 -0400
commitdd78c9439fc1e031835bccb934d27b978c72c536 (patch)
tree003eb90233367defab682643dc1cc143a302dc68
parent63a10dfdda0e2262f5b61b54b6d9b1747a87ff54 (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>
-rw-r--r--drivers/char/tpm/tpm.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
index aa899cec6b3f..e70d13defde4 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,
1187 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 1187 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1188 devname = kmalloc(DEVNAME_SIZE, GFP_KERNEL); 1188 devname = kmalloc(DEVNAME_SIZE, GFP_KERNEL);
1189 1189
1190 if (chip == NULL || devname == NULL) { 1190 if (chip == NULL || devname == NULL)
1191 kfree(chip); 1191 goto out_free;
1192 kfree(devname);
1193 return NULL;
1194 }
1195 1192
1196 mutex_init(&chip->buffer_mutex); 1193 mutex_init(&chip->buffer_mutex);
1197 mutex_init(&chip->tpm_mutex); 1194 mutex_init(&chip->tpm_mutex);
@@ -1208,8 +1205,7 @@ struct tpm_chip *tpm_register_hardware(struct device *dev,
1208 1205
1209 if (chip->dev_num >= TPM_NUM_DEVICES) { 1206 if (chip->dev_num >= TPM_NUM_DEVICES) {
1210 dev_err(dev, "No available tpm device numbers\n"); 1207 dev_err(dev, "No available tpm device numbers\n");
1211 kfree(chip); 1208 goto out_free;
1212 return NULL;
1213 } else if (chip->dev_num == 0) 1209 } else if (chip->dev_num == 0)
1214 chip->vendor.miscdev.minor = TPM_MINOR; 1210 chip->vendor.miscdev.minor = TPM_MINOR;
1215 else 1211 else
@@ -1250,6 +1246,11 @@ struct tpm_chip *tpm_register_hardware(struct device *dev,
1250 spin_unlock(&driver_lock); 1246 spin_unlock(&driver_lock);
1251 1247
1252 return chip; 1248 return chip;
1249
1250out_free:
1251 kfree(chip);
1252 kfree(devname);
1253 return NULL;
1253} 1254}
1254EXPORT_SYMBOL_GPL(tpm_register_hardware); 1255EXPORT_SYMBOL_GPL(tpm_register_hardware);
1255 1256