[PATCH AUTOSEL 4.4 18/65] tpm: fix: return rc when devm_add_action() fails

From: Sasha Levin
Date: Thu Oct 25 2018 - 10:35:05 EST


From: Jarkko Sakkinen <jarkko.sakkinen@xxxxxxxxxxxxxxx>

[ Upstream commit 4f3b193dee4423d8c89c9a3e8e05f9197ea459a4 ]

Call put_device() and return error code if devm_add_action() fails.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@xxxxxxxxxxxxxxx>
Reported-by: Jason Gunthorpe <jgunthorpe@xxxxxxxxxxxxxxxxxxxx>
Fixes: 8e0ee3c9faed ("tpm: fix the cleanup of struct tpm_chip")
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
drivers/char/tpm/tpm-chip.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index e759100e41a7..28894878dcd5 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -230,7 +230,11 @@ struct tpm_chip *tpmm_chip_alloc(struct device *dev,
chip->cdev.owner = dev->driver->owner;
chip->cdev.kobj.parent = &chip->dev.kobj;

- devm_add_action(dev, (void (*)(void *)) put_device, &chip->dev);
+ rc = devm_add_action(dev, (void (*)(void *)) put_device, &chip->dev);
+ if (rc) {
+ put_device(&chip->dev);
+ return ERR_PTR(rc);
+ }

return chip;
}
--
2.17.1