* [PATCH v3 01/11] tpm: fix the cleanup of struct tpm_chip
[not found] <1455885728-10315-1-git-send-email-stefanb@linux.vnet.ibm.com>
@ 2016-02-19 12:41 ` Stefan Berger
0 siblings, 0 replies; only message in thread
From: Stefan Berger @ 2016-02-19 12:41 UTC (permalink / raw)
To: tpmdd-devel; +Cc: jarkko.sakkinen, jgunthorpe, stable
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
If the initialization fails before tpm_chip_register(), put_device()
will be not called, which causes release callback not to be called.
This patch fixes the issue by adding put_device() to devres list of
the parent device.
Fixes: 313d21eeab ("tpm: device class for tpm")
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
cc: stable@vger.kernel.org
---
drivers/char/tpm/tpm-chip.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index 45cc39a..ab32437 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -88,6 +88,7 @@ struct tpm_chip *tpmm_chip_alloc(struct device *dev,
const struct tpm_class_ops *ops)
{
struct tpm_chip *chip;
+ int err;
chip = kzalloc(sizeof(*chip), GFP_KERNEL);
if (chip == NULL)
@@ -136,6 +137,12 @@ struct tpm_chip *tpmm_chip_alloc(struct device *dev,
chip->cdev.owner = chip->pdev->driver->owner;
chip->cdev.kobj.parent = &chip->dev.kobj;
+ err = devm_add_action(dev, (void (*)(void *)) put_device, &chip->dev);
+ if (err) {
+ put_device(&chip->dev);
+ return ERR_PTR(err);
+ }
+
return chip;
}
EXPORT_SYMBOL_GPL(tpmm_chip_alloc);
@@ -171,7 +178,7 @@ static int tpm_dev_add_device(struct tpm_chip *chip)
static void tpm_dev_del_device(struct tpm_chip *chip)
{
cdev_del(&chip->cdev);
- device_unregister(&chip->dev);
+ device_del(&chip->dev);
}
static int tpm1_chip_register(struct tpm_chip *chip)
--
2.4.3
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2016-02-19 12:42 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1455885728-10315-1-git-send-email-stefanb@linux.vnet.ibm.com>
2016-02-19 12:41 ` [PATCH v3 01/11] tpm: fix the cleanup of struct tpm_chip Stefan Berger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).