All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lino Sanfilippo <LinoSanfilippo@gmx.de>
To: peterhuewe@gmx.de, jarkko@kernel.org
Cc: jgg@ziepe.ca, stefanb@linux.vnet.ibm.com,
	linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org,
	LinoSanfilippo@gmx.de, p.rosenberger@kunbus.com,
	Lino Sanfilippo <l.sanfilippo@kunbus.com>
Subject: [PATCH 1/4] tpm: in case of error properly cleanup in tpmm_chip_alloc
Date: Sat, 16 Jan 2021 02:22:38 +0100	[thread overview]
Message-ID: <1610760161-21982-2-git-send-email-LinoSanfilippo@gmx.de> (raw)
In-Reply-To: <1610760161-21982-1-git-send-email-LinoSanfilippo@gmx.de>

From: Lino Sanfilippo <l.sanfilippo@kunbus.com>

In tpmm_chip_alloc() a resource management action handler is installed to
release the chip->dev in case of error. This will result in the chip being
freed if it was the last reference. If the installation of the handler was
not successful an error is returned to the caller.
However in this case the chip->dev reference is not put and thus the chip
is never freed. Fix this by releasing the reference "by hand" in case that
the action handler installation failed.

Signed-off-by: Lino Sanfilippo <l.sanfilippo@kunbus.com>
---
 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 ddaeceb..e242d2e 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -423,11 +423,15 @@ struct tpm_chip *tpmm_chip_alloc(struct device *pdev,
 				      (void (*)(void *)) put_device,
 				      &chip->dev);
 	if (rc)
-		return ERR_PTR(rc);
+		goto put_dev;
 
 	dev_set_drvdata(pdev, chip);
 
 	return chip;
+
+put_dev:
+	put_device(&chip->dev);
+	return ERR_PTR(rc);
 }
 EXPORT_SYMBOL_GPL(tpmm_chip_alloc);
 
-- 
2.7.4


  reply	other threads:[~2021-01-16  1:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-16  1:22 [PATCH 0/4] TPM fixes Lino Sanfilippo
2021-01-16  1:22 ` Lino Sanfilippo [this message]
2021-01-17 18:08   ` [PATCH 1/4] tpm: in case of error properly cleanup in tpmm_chip_alloc Jarkko Sakkinen
2021-01-16  1:22 ` [PATCH 2/4] tpm: fix reference counting for struct tpm_chip Lino Sanfilippo
2021-01-17 18:11   ` Jarkko Sakkinen
2021-01-16  1:22 ` [PATCH 3/4] tpm: in tpm2_del_space check if ops pointer is still valid Lino Sanfilippo
2021-01-17 18:13   ` Jarkko Sakkinen
2021-01-24 16:47     ` Lino Sanfilippo
2021-01-26 15:29       ` Jarkko Sakkinen
2021-01-27 15:14         ` Lino Sanfilippo
2021-01-16  1:22 ` [PATCH 4/4] tpm: Provide a function tpm_chip_free() to free tpm chips Lino Sanfilippo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1610760161-21982-2-git-send-email-LinoSanfilippo@gmx.de \
    --to=linosanfilippo@gmx.de \
    --cc=jarkko@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=l.sanfilippo@kunbus.com \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=p.rosenberger@kunbus.com \
    --cc=peterhuewe@gmx.de \
    --cc=stefanb@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.