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 4/4] tpm: Provide a function tpm_chip_free() to free tpm chips
Date: Sat, 16 Jan 2021 02:22:41 +0100	[thread overview]
Message-ID: <1610760161-21982-5-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>

Provide a function tpm_chip_free() as a counterpart to tpm_chip_alloc().
The function hides the internals of freeing a struct tpm_chip instance
by putting the device references which are part of this structure.

Use the new function at the appropriate places.

Signed-off-by: Lino Sanfilippo <l.sanfilippo@kunbus.com>
---
 drivers/char/tpm/tpm-chip.c       | 16 ++++++++++++++++
 drivers/char/tpm/tpm.h            |  1 +
 drivers/char/tpm/tpm_ftpm_tee.c   |  6 ++----
 drivers/char/tpm/tpm_vtpm_proxy.c |  3 +--
 4 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index 596824c..85e987b 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -402,6 +402,22 @@ struct tpm_chip *tpm_chip_alloc(struct device *pdev,
 EXPORT_SYMBOL_GPL(tpm_chip_alloc);
 
 /**
+ * tpm_chip_free() - free an instance of struct tpm_chip that has been
+ * allocated with tpm_chip_alloc() before.
+ * @chip: chip to free
+ *
+ * Frees an instance of struct tpm_chip by releasing internal device references.
+ * This function is used to hide the internals needed to free a struct tpm_chip
+ * instance thas has been allocated with tpm_chip_alloc() before.
+ */
+void tpm_chip_free(struct tpm_chip *chip)
+{
+	put_device(&chip->devs);
+	put_device(&chip->dev);
+}
+EXPORT_SYMBOL_GPL(tpm_chip_free);
+
+/**
  * tpmm_chip_alloc() - allocate a new struct tpm_chip instance
  * @pdev: parent device to which the chip is associated
  * @ops: struct tpm_class_ops instance
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 947d1db..e6bb6ae 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -199,6 +199,7 @@ void tpm_put_ops(struct tpm_chip *chip);
 
 struct tpm_chip *tpm_chip_alloc(struct device *dev,
 				const struct tpm_class_ops *ops);
+void tpm_chip_free(struct tpm_chip *chip);
 struct tpm_chip *tpmm_chip_alloc(struct device *pdev,
 				 const struct tpm_class_ops *ops);
 int tpm_chip_register(struct tpm_chip *chip);
diff --git a/drivers/char/tpm/tpm_ftpm_tee.c b/drivers/char/tpm/tpm_ftpm_tee.c
index 82858c2..47ffaae 100644
--- a/drivers/char/tpm/tpm_ftpm_tee.c
+++ b/drivers/char/tpm/tpm_ftpm_tee.c
@@ -285,8 +285,7 @@ static int ftpm_tee_probe(struct device *dev)
 	return 0;
 
 out_chip:
-	put_device(&pvt_data->chip->dev);
-	put_device(&pvt_data->chip->devs);
+	tpm_chip_free(chip);
 out_chip_alloc:
 	tee_shm_free(pvt_data->shm);
 out_shm_alloc:
@@ -319,8 +318,7 @@ static int ftpm_tee_remove(struct device *dev)
 	tpm_chip_unregister(pvt_data->chip);
 
 	/* frees chip */
-	put_device(&pvt_data->chip->devs);
-	put_device(&pvt_data->chip->dev);
+	tpm_chip_free(pvt_data->chip);
 
 	/* Free the shared memory pool */
 	tee_shm_free(pvt_data->shm);
diff --git a/drivers/char/tpm/tpm_vtpm_proxy.c b/drivers/char/tpm/tpm_vtpm_proxy.c
index 97b60f8..f887bb3 100644
--- a/drivers/char/tpm/tpm_vtpm_proxy.c
+++ b/drivers/char/tpm/tpm_vtpm_proxy.c
@@ -520,8 +520,7 @@ static struct proxy_dev *vtpm_proxy_create_proxy_dev(void)
  */
 static inline void vtpm_proxy_delete_proxy_dev(struct proxy_dev *proxy_dev)
 {
-	put_device(&proxy_dev->chip->devs);
-	put_device(&proxy_dev->chip->dev); /* frees chip */
+	tpm_chip_free(proxy_dev->chip);
 	kfree(proxy_dev);
 }
 
-- 
2.7.4


      parent 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 ` [PATCH 1/4] tpm: in case of error properly cleanup in tpmm_chip_alloc Lino Sanfilippo
2021-01-17 18:08   ` 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 ` Lino Sanfilippo [this message]

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-5-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.