diff options
author | Jason Gunthorpe <jgunthorpe@obsidianresearch.com> | 2016-02-11 14:45:48 -0500 |
---|---|---|
committer | Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> | 2016-06-25 10:26:35 -0400 |
commit | 3897cd9c8d1d1a9ff81fed893502911c2b9f4a79 (patch) | |
tree | 99163c28d3a81511d014541c597c0c32979feca0 | |
parent | 2072df40ec19d9703adfcdbd15f30c879bb65b2a (diff) |
tpm: Split out the devm stuff from tpmm_chip_alloc
tpm_chip_alloc becomes a typical subsystem allocate call.
Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Tested-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
-rw-r--r-- | drivers/char/tpm/tpm-chip.c | 49 | ||||
-rw-r--r-- | drivers/char/tpm/tpm.h | 4 |
2 files changed, 38 insertions, 15 deletions
diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index 66367286deea..588037733107 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c | |||
@@ -121,17 +121,17 @@ static void tpm_dev_release(struct device *dev) | |||
121 | } | 121 | } |
122 | 122 | ||
123 | /** | 123 | /** |
124 | * tpmm_chip_alloc() - allocate a new struct tpm_chip instance | 124 | * tpm_chip_alloc() - allocate a new struct tpm_chip instance |
125 | * @dev: device to which the chip is associated | 125 | * @pdev: device to which the chip is associated |
126 | * At this point pdev mst be initialized, but does not have to | ||
127 | * be registered | ||
126 | * @ops: struct tpm_class_ops instance | 128 | * @ops: struct tpm_class_ops instance |
127 | * | 129 | * |
128 | * Allocates a new struct tpm_chip instance and assigns a free | 130 | * Allocates a new struct tpm_chip instance and assigns a free |
129 | * device number for it. Caller does not have to worry about | 131 | * device number for it. Must be paired with put_device(&chip->dev). |
130 | * freeing the allocated resources. When the devices is removed | ||
131 | * devres calls tpmm_chip_remove() to do the job. | ||
132 | */ | 132 | */ |
133 | struct tpm_chip *tpmm_chip_alloc(struct device *dev, | 133 | struct tpm_chip *tpm_chip_alloc(struct device *dev, |
134 | const struct tpm_class_ops *ops) | 134 | const struct tpm_class_ops *ops) |
135 | { | 135 | { |
136 | struct tpm_chip *chip; | 136 | struct tpm_chip *chip; |
137 | int rc; | 137 | int rc; |
@@ -160,8 +160,6 @@ struct tpm_chip *tpmm_chip_alloc(struct device *dev, | |||
160 | 160 | ||
161 | device_initialize(&chip->dev); | 161 | device_initialize(&chip->dev); |
162 | 162 | ||
163 | dev_set_drvdata(dev, chip); | ||
164 | |||
165 | chip->dev.class = tpm_class; | 163 | chip->dev.class = tpm_class; |
166 | chip->dev.release = tpm_dev_release; | 164 | chip->dev.release = tpm_dev_release; |
167 | chip->dev.parent = dev; | 165 | chip->dev.parent = dev; |
@@ -182,17 +180,40 @@ struct tpm_chip *tpmm_chip_alloc(struct device *dev, | |||
182 | chip->cdev.owner = THIS_MODULE; | 180 | chip->cdev.owner = THIS_MODULE; |
183 | chip->cdev.kobj.parent = &chip->dev.kobj; | 181 | chip->cdev.kobj.parent = &chip->dev.kobj; |
184 | 182 | ||
185 | rc = devm_add_action(dev, (void (*)(void *)) put_device, &chip->dev); | 183 | return chip; |
184 | |||
185 | out: | ||
186 | put_device(&chip->dev); | ||
187 | return ERR_PTR(rc); | ||
188 | } | ||
189 | EXPORT_SYMBOL_GPL(tpm_chip_alloc); | ||
190 | |||
191 | /** | ||
192 | * tpmm_chip_alloc() - allocate a new struct tpm_chip instance | ||
193 | * @pdev: parent device to which the chip is associated | ||
194 | * @ops: struct tpm_class_ops instance | ||
195 | * | ||
196 | * Same as tpm_chip_alloc except devm is used to do the put_device | ||
197 | */ | ||
198 | struct tpm_chip *tpmm_chip_alloc(struct device *pdev, | ||
199 | const struct tpm_class_ops *ops) | ||
200 | { | ||
201 | struct tpm_chip *chip; | ||
202 | int rc; | ||
203 | |||
204 | chip = tpm_chip_alloc(pdev, ops); | ||
205 | if (IS_ERR(chip)) | ||
206 | return chip; | ||
207 | |||
208 | rc = devm_add_action(pdev, (void (*)(void *)) put_device, &chip->dev); | ||
186 | if (rc) { | 209 | if (rc) { |
187 | put_device(&chip->dev); | 210 | put_device(&chip->dev); |
188 | return ERR_PTR(rc); | 211 | return ERR_PTR(rc); |
189 | } | 212 | } |
190 | 213 | ||
191 | return chip; | 214 | dev_set_drvdata(pdev, chip); |
192 | 215 | ||
193 | out: | 216 | return chip; |
194 | put_device(&chip->dev); | ||
195 | return ERR_PTR(rc); | ||
196 | } | 217 | } |
197 | EXPORT_SYMBOL_GPL(tpmm_chip_alloc); | 218 | EXPORT_SYMBOL_GPL(tpmm_chip_alloc); |
198 | 219 | ||
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index c6376b174fbe..5fcf7885a4b9 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h | |||
@@ -511,7 +511,9 @@ struct tpm_chip *tpm_chip_find_get(int chip_num); | |||
511 | __must_check int tpm_try_get_ops(struct tpm_chip *chip); | 511 | __must_check int tpm_try_get_ops(struct tpm_chip *chip); |
512 | void tpm_put_ops(struct tpm_chip *chip); | 512 | void tpm_put_ops(struct tpm_chip *chip); |
513 | 513 | ||
514 | extern struct tpm_chip *tpmm_chip_alloc(struct device *dev, | 514 | extern struct tpm_chip *tpm_chip_alloc(struct device *dev, |
515 | const struct tpm_class_ops *ops); | ||
516 | extern struct tpm_chip *tpmm_chip_alloc(struct device *pdev, | ||
515 | const struct tpm_class_ops *ops); | 517 | const struct tpm_class_ops *ops); |
516 | extern int tpm_chip_register(struct tpm_chip *chip); | 518 | extern int tpm_chip_register(struct tpm_chip *chip); |
517 | extern void tpm_chip_unregister(struct tpm_chip *chip); | 519 | extern void tpm_chip_unregister(struct tpm_chip *chip); |