diff mbox

[v5,1/5] Implement tpm_chip_free

Message ID 1454959628-30582-2-git-send-email-stefanb@linux.vnet.ibm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Stefan Berger Feb. 8, 2016, 7:27 p.m. UTC
Implement the public function tpm_chip_free to undo tpmm_chip_alloc.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
---
 drivers/char/tpm/tpm-chip.c | 14 ++++++++++----
 drivers/char/tpm/tpm.h      |  1 +
 2 files changed, 11 insertions(+), 4 deletions(-)

Comments

Jason Gunthorpe Feb. 9, 2016, 5:28 a.m. UTC | #1
On Mon, Feb 08, 2016 at 02:27:04PM -0500, Stefan Berger wrote:
> Implement the public function tpm_chip_free to undo tpmm_chip_alloc.

No, this is wrong, chip cannot be kfree'd like that.

tpmm needs to rely on devm for cleanup.

Jason

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
diff mbox

Patch

diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index fbd75c5..361cee8 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -59,6 +59,15 @@  struct tpm_chip *tpm_chip_find_get(int chip_num)
 }
 EXPORT_SYMBOL_GPL(tpm_chip_find_get);
 
+void tpm_chip_free(struct tpm_chip *chip)
+{
+	spin_lock(&driver_lock);
+	clear_bit(chip->dev_num, dev_mask);
+	spin_unlock(&driver_lock);
+	kfree(chip);
+}
+EXPORT_SYMBOL_GPL(tpm_chip_free);
+
 /**
  * tpm_dev_release() - free chip memory and the device number
  * @dev: the character device for the TPM chip
@@ -69,10 +78,7 @@  static void tpm_dev_release(struct device *dev)
 {
 	struct tpm_chip *chip = container_of(dev, struct tpm_chip, dev);
 
-	spin_lock(&driver_lock);
-	clear_bit(chip->dev_num, dev_mask);
-	spin_unlock(&driver_lock);
-	kfree(chip);
+	tpm_chip_free(chip);
 }
 
 /**
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index a4257a3..440a167 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -515,6 +515,7 @@  extern int wait_for_tpm_stat(struct tpm_chip *, u8, unsigned long,
 struct tpm_chip *tpm_chip_find_get(int chip_num);
 extern struct tpm_chip *tpmm_chip_alloc(struct device *dev,
 				       const struct tpm_class_ops *ops);
+extern void tpm_chip_free(struct tpm_chip *chip);
 extern int tpm_chip_register(struct tpm_chip *chip);
 extern void tpm_chip_unregister(struct tpm_chip *chip);