linux-integrity.vger.kernel.org archive mirror
 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, Lino Sanfilippo <l.sanfilippo@kunbus.com>
Subject: [PATCH v2 2/3] tpm: Provide a function tpm_chip_free() to free tpm chips
Date: Tue,  2 Feb 2021 23:09:02 +0100	[thread overview]
Message-ID: <1612303743-29017-3-git-send-email-LinoSanfilippo@gmx.de> (raw)
In-Reply-To: <1612303743-29017-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 3ace199..777baae 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-02-02 22:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-02 22:09 [PATCH v2 0/3] TPM fixes Lino Sanfilippo
2021-02-02 22:09 ` [PATCH v2 1/3] tpm: fix reference counting for struct tpm_chip Lino Sanfilippo
2021-02-03  1:09   ` Jarkko Sakkinen
2021-02-03 14:06     ` Lino Sanfilippo
2021-02-03 21:43       ` Jarkko Sakkinen
2021-02-02 22:09 ` Lino Sanfilippo [this message]
2021-02-03  1:28   ` [PATCH v2 2/3] tpm: Provide a function tpm_chip_free() to free tpm chips Jarkko Sakkinen
2021-02-03 14:09     ` Lino Sanfilippo
2021-02-02 22:09 ` [PATCH v2 3/3] tpm: in tpm2_del_space check if ops pointer is still valid Lino Sanfilippo
2021-02-03  1:17   ` Jarkko Sakkinen
2021-02-03 14:22     ` 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=1612303743-29017-3-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=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 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).