mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-23 17:30:02 +00:00
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>
This commit is contained in:
parent
2072df40ec
commit
3897cd9c8d
2 changed files with 39 additions and 16 deletions
|
@ -121,17 +121,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 rc;
|
||||
|
@ -160,8 +160,6 @@ struct tpm_chip *tpmm_chip_alloc(struct device *dev,
|
|||
|
||||
device_initialize(&chip->dev);
|
||||
|
||||
dev_set_drvdata(dev, chip);
|
||||
|
||||
chip->dev.class = tpm_class;
|
||||
chip->dev.release = tpm_dev_release;
|
||||
chip->dev.parent = dev;
|
||||
|
@ -182,18 +180,41 @@ struct tpm_chip *tpmm_chip_alloc(struct device *dev,
|
|||
chip->cdev.owner = THIS_MODULE;
|
||||
chip->cdev.kobj.parent = &chip->dev.kobj;
|
||||
|
||||
rc = devm_add_action(dev, (void (*)(void *)) put_device, &chip->dev);
|
||||
if (rc) {
|
||||
put_device(&chip->dev);
|
||||
return ERR_PTR(rc);
|
||||
}
|
||||
|
||||
return chip;
|
||||
|
||||
out:
|
||||
put_device(&chip->dev);
|
||||
return ERR_PTR(rc);
|
||||
}
|
||||
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 rc;
|
||||
|
||||
chip = tpm_chip_alloc(pdev, ops);
|
||||
if (IS_ERR(chip))
|
||||
return chip;
|
||||
|
||||
rc = devm_add_action(pdev, (void (*)(void *)) put_device, &chip->dev);
|
||||
if (rc) {
|
||||
put_device(&chip->dev);
|
||||
return ERR_PTR(rc);
|
||||
}
|
||||
|
||||
dev_set_drvdata(pdev, chip);
|
||||
|
||||
return chip;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(tpmm_chip_alloc);
|
||||
|
||||
static int tpm_add_char_device(struct tpm_chip *chip)
|
||||
|
|
|
@ -511,7 +511,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);
|
||||
|
|
Loading…
Reference in a new issue