All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Berger <stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
To: tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: [PATCH v3 06/11] tpm: Split out the devm stuff from tpmm_chip_alloc
Date: Fri, 19 Feb 2016 07:42:03 -0500	[thread overview]
Message-ID: <1455885728-10315-7-git-send-email-stefanb@linux.vnet.ibm.com> (raw)
In-Reply-To: <1455885728-10315-1-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>

From: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>

tpm_chip_alloc becomes a typical subsystem allocate call.

Signed-off-by: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
---
 drivers/char/tpm/tpm-chip.c | 57 +++++++++++++++++++++++++++++++--------------
 drivers/char/tpm/tpm.h      |  4 +++-
 2 files changed, 42 insertions(+), 19 deletions(-)

diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index fe15637..2270e47 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -120,17 +120,17 @@ static void tpm_dev_release(struct device *dev)
 }
 
 /**
- * tpmm_chip_alloc() - allocate a new struct tpm_chip instance
- * @dev: device to which the chip is associated
+ * tpm_chip_alloc() - allocate a new struct tpm_chip instance
+ * @pdev: device to which the chip is associated
+ *        At this point pdev mst be initialized, but does not have to
+ *        be registered
  * @ops: struct tpm_class_ops instance
  *
  * Allocates a new struct tpm_chip instance and assigns a free
- * device number for it. Caller does not have to worry about
- * freeing the allocated resources. When the devices is removed
- * devres calls tpmm_chip_remove() to do the job.
+ * device number for it. Must be paired with put_device(&chip->dev).
  */
-struct tpm_chip *tpmm_chip_alloc(struct device *dev,
-				 const struct tpm_class_ops *ops)
+struct tpm_chip *tpm_chip_alloc(struct device *dev,
+				const struct tpm_class_ops *ops)
 {
 	struct tpm_chip *chip;
 	int err;
@@ -143,10 +143,10 @@ struct tpm_chip *tpmm_chip_alloc(struct device *dev,
 	mutex_init(&chip->tpm_mutex);
 	INIT_LIST_HEAD(&chip->list);
 
-	chip->ops = ops;
-
 	spin_lock(&driver_lock);
 	chip->dev_num = find_first_zero_bit(dev_mask, TPM_NUM_DEVICES);
+	if (chip->dev_num < TPM_NUM_DEVICES)
+		set_bit(chip->dev_num, dev_mask);
 	spin_unlock(&driver_lock);
 
 	if (chip->dev_num >= TPM_NUM_DEVICES) {
@@ -155,9 +155,9 @@ struct tpm_chip *tpmm_chip_alloc(struct device *dev,
 		return ERR_PTR(-ENOMEM);
 	}
 
-	set_bit(chip->dev_num, dev_mask);
+	chip->ops = ops;
 
-	dev_set_drvdata(dev, chip);
+	device_initialize(&chip->dev);
 
 	chip->dev.class = tpm_class;
 	chip->dev.release = tpm_dev_release;
@@ -175,23 +175,44 @@ struct tpm_chip *tpmm_chip_alloc(struct device *dev,
 	if (err)
 		goto out;
 
-	device_initialize(&chip->dev);
-
 	cdev_init(&chip->cdev, &tpm_fops);
 	chip->cdev.owner = dev->driver->owner;
 	chip->cdev.kobj.parent = &chip->dev.kobj;
 
-	err = devm_add_action(dev, (void (*)(void *)) put_device, &chip->dev);
+	return chip;
+
+out:
+	put_device(&chip->dev);
+	return ERR_PTR(err);
+}
+EXPORT_SYMBOL_GPL(tpm_chip_alloc);
+
+/**
+ * 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
+ *
+ * Same as tpm_chip_alloc except devm is used to do the put_device
+ */
+struct tpm_chip *tpmm_chip_alloc(struct device *pdev,
+				 const struct tpm_class_ops *ops)
+{
+	struct tpm_chip *chip;
+	int err;
+
+	chip = tpm_chip_alloc(pdev, ops);
+	if (IS_ERR(chip))
+		return chip;
+
+	err = devm_add_action(pdev, (void (*)(void *)) put_device, &chip->dev);
 	if (err) {
 		put_device(&chip->dev);
 		return ERR_PTR(err);
 	}
 
-	return chip;
+	dev_set_drvdata(pdev, chip);
 
-out:
-	put_device(&chip->dev);
-	return ERR_PTR(err);
+	return chip;
 }
 EXPORT_SYMBOL_GPL(tpmm_chip_alloc);
 
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 2a8373e..25efe8f 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -515,7 +515,9 @@ struct tpm_chip *tpm_chip_find_get(int chip_num);
 __must_check int tpm_try_get_ops(struct tpm_chip *chip);
 void tpm_put_ops(struct tpm_chip *chip);
 
-extern struct tpm_chip *tpmm_chip_alloc(struct device *dev,
+extern struct tpm_chip *tpm_chip_alloc(struct device *dev,
+				       const struct tpm_class_ops *ops);
+extern struct tpm_chip *tpmm_chip_alloc(struct device *pdev,
 				       const struct tpm_class_ops *ops);
 extern int tpm_chip_register(struct tpm_chip *chip);
 extern void tpm_chip_unregister(struct tpm_chip *chip);
-- 
2.4.3


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

  parent reply	other threads:[~2016-02-19 12:42 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-19 12:41 [PATCH v3 00/11] Multi-instance vTPM driver Stefan Berger
2016-02-19 12:41 ` [PATCH v3 01/11] tpm: fix the cleanup of struct tpm_chip Stefan Berger
     [not found] ` <1455885728-10315-1-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-02-19 12:41   ` [PATCH v3 02/11] tpm: Get rid of chip->pdev Stefan Berger
     [not found]     ` <1455885728-10315-3-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-02-22 19:25       ` Jarkko Sakkinen
2016-02-19 12:42   ` [PATCH v3 03/11] tpm: Get rid of devname Stefan Berger
     [not found]     ` <1455885728-10315-4-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-02-22 18:19       ` Jason Gunthorpe
     [not found]         ` <20160222181929.GB22088-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-22 19:42           ` Jarkko Sakkinen
     [not found]             ` <20160222194202.GC32667-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-02-22 19:58               ` Jason Gunthorpe
     [not found]                 ` <20160222195816.GL22088-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-22 20:34                   ` Jason Gunthorpe
2016-02-23  0:22           ` Stefan Berger
2016-02-19 12:42   ` [PATCH v3 04/11] tpm: Provide strong locking for device removal Stefan Berger
     [not found]     ` <1455885728-10315-5-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-02-22 21:08       ` Jarkko Sakkinen
     [not found]         ` <20160222210844.GA3310-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-02-22 22:20           ` Jason Gunthorpe
     [not found]             ` <20160222222017.GC27228-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-23 19:40               ` Jarkko Sakkinen
     [not found]                 ` <20160223194014.GA5241-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-02-23 19:52                   ` Jason Gunthorpe
     [not found]                     ` <20160223195246.GC389-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-23 20:36                       ` Jarkko Sakkinen
2016-02-23 20:43               ` Jarkko Sakkinen
2016-02-19 12:42   ` [PATCH v3 05/11] tpm: Get rid of module locking Stefan Berger
     [not found]     ` <1455885728-10315-6-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-02-22 18:22       ` Jason Gunthorpe
     [not found]         ` <20160222182245.GC22088-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-23  0:26           ` Stefan Berger
2016-02-22 21:11       ` Jarkko Sakkinen
     [not found]         ` <20160222211141.GB3310-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-02-22 22:15           ` Jason Gunthorpe
2016-02-19 12:42   ` Stefan Berger [this message]
     [not found]     ` <1455885728-10315-7-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-02-22 18:24       ` [PATCH v3 06/11] tpm: Split out the devm stuff from tpmm_chip_alloc Jason Gunthorpe
2016-02-22 21:14       ` Jarkko Sakkinen
     [not found]         ` <20160222211414.GC3310-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-02-22 22:13           ` Jason Gunthorpe
     [not found]             ` <20160222221328.GA27228-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-23  0:45               ` Stefan Berger
2016-02-23 11:31               ` Jarkko Sakkinen
2016-02-19 12:42   ` [PATCH v3 07/11] tpm: Replace device number bitmap with IDR Stefan Berger
     [not found]     ` <1455885728-10315-8-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-02-22 19:06       ` Jason Gunthorpe
     [not found]         ` <20160222190629.GE22088-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-23  1:15           ` Stefan Berger
2016-02-23  2:16           ` Stefan Berger
     [not found]         ` <201602230116.u1N1G4iu012263@d03av02.boulder.ibm.com>
     [not found]           ` <201602230116.u1N1G4iu012263-nNA/7dmquNI+UXBhvPuGgqsjOiXwFzmk@public.gmane.org>
2016-02-23  2:16             ` Jason Gunthorpe
     [not found]               ` <20160223021606.GC26177-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-23 23:04                 ` Stefan Berger
     [not found]               ` <201602232305.u1NN521L020589@d03av01.boulder.ibm.com>
     [not found]                 ` <201602232305.u1NN521L020589-Rn83F4s8Lwc+UXBhvPuGgqsjOiXwFzmk@public.gmane.org>
2016-02-23 23:18                   ` Jason Gunthorpe
     [not found]         ` <201602230217.u1N2HIJT003183@d03av05.boulder.ibm.com>
     [not found]           ` <201602230217.u1N2HIJT003183-3MP/CPU4Muo+UXBhvPuGgqsjOiXwFzmk@public.gmane.org>
2016-02-23  2:18             ` Jason Gunthorpe
2016-02-19 12:42   ` [PATCH v3 08/11] tpm: Introduce TPM_CHIP_FLAG_VIRTUAL Stefan Berger
     [not found]     ` <1455885728-10315-9-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-02-22 19:19       ` Jason Gunthorpe
     [not found]         ` <20160222191922.GH22088-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-23  1:20           ` [PATCH v3 08/11] tpm: IntroduceTPM_CHIP_FLAG_VIRTUAL Stefan Berger
2016-02-23  1:21           ` Stefan Berger
     [not found]         ` <201602230121.u1N1LYk2024786@d01av01.pok.ibm.com>
     [not found]           ` <201602230121.u1N1LYk2024786-4ZtxiNBBw+3ImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-02-23  2:05             ` Jason Gunthorpe
     [not found]               ` <20160223020515.GA26177-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-23  3:40                 ` Stefan Berger
     [not found]         ` <201602230116.u1N1Ghac006778@d01av05.pok.ibm.com>
     [not found]           ` <201602230116.u1N1Ghac006778-8DuMPbUlb4HImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-02-23  2:06             ` Jason Gunthorpe
2016-02-19 12:42   ` [PATCH v3 09/11] tpm: Driver for supporting multiple emulated TPMs Stefan Berger
     [not found]     ` <1455885728-10315-10-git-send-email-stefanb-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-02-22 19:27       ` Jason Gunthorpe
     [not found]         ` <20160222192741.GI22088-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-23  1:45           ` Stefan Berger
     [not found]         ` <201602230142.u1N1gSuF029481@d01av05.pok.ibm.com>
     [not found]           ` <201602230142.u1N1gSuF029481-8DuMPbUlb4HImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-02-23  2:17             ` Jason Gunthorpe
     [not found]               ` <20160223021730.GD26177-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-24 23:10                 ` Stefan Berger
     [not found]                   ` <201602242306.u1ON6qGP030251-8DuMPbUlb4HImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-02-25 13:17                     ` Jarkko Sakkinen
     [not found]                       ` <20160225131732.GA20860-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-02-25 14:12                         ` Stefan Berger
     [not found]                       ` <201602251409.u1PE98LH012367@d01av05.pok.ibm.com>
     [not found]                         ` <201602251409.u1PE98LH012367-8DuMPbUlb4HImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-02-25 17:39                           ` Jason Gunthorpe
     [not found]                             ` <20160225173956.GA1407-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-25 18:42                               ` Stefan Berger
     [not found]                             ` <201602251842.u1PIgEuL014249@d03av03.boulder.ibm.com>
     [not found]                               ` <201602251842.u1PIgEuL014249-MijUUJkLaQs+UXBhvPuGgqsjOiXwFzmk@public.gmane.org>
2016-02-25 20:31                                 ` Jason Gunthorpe
     [not found]                                   ` <20160225203117.GA22984-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-02-25 22:11                                     ` Stefan Berger
2016-02-23 10:22       ` Jarkko Sakkinen
     [not found]         ` <20160223102211.GA9474-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-02-23 12:09           ` Stefan Berger
     [not found]         ` <201602231210.u1NCAD6D017196@d01av03.pok.ibm.com>
     [not found]           ` <201602231210.u1NCAD6D017196-CUdSWdNILC7ImUpY6SP3GEEOCMrvLtNR@public.gmane.org>
2016-02-23 18:36             ` Jarkko Sakkinen
2016-02-19 12:42   ` [PATCH v3 10/11] tpm: Initialize TPM and get durations and timeouts Stefan Berger
2016-02-19 12:42   ` [PATCH v3 11/11] A test program for vTPM device creation Stefan Berger
2016-02-22 19:20   ` [PATCH v3 00/11] Multi-instance vTPM driver Jarkko Sakkinen

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=1455885728-10315-7-git-send-email-stefanb@linux.vnet.ibm.com \
    --to=stefanb-23vcf4htsmix0ybbhkvfkdbpr1lh4cv8@public.gmane.org \
    --cc=tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    /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.