Skip to content

Commit

Permalink
TPM: fix memleak when register hardware fails
Browse files Browse the repository at this point in the history
Adding proper kfree() before returning.

Signed-off-by: Wanlong Gao <[email protected]>
Signed-off-by: Rajiv Andrade <[email protected]>
  • Loading branch information
gaowanlong authored and srajiv committed Jun 12, 2012
1 parent 24ebe66 commit dad79cb
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions drivers/char/tpm/tpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1413,15 +1413,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);
Expand All @@ -1433,6 +1430,8 @@ struct tpm_chip *tpm_register_hardware(struct device *dev,

return chip;

put_device:
put_device(chip->dev);
out_free:
kfree(chip);
kfree(devname);
Expand Down

0 comments on commit dad79cb

Please sign in to comment.