Jason Gunthorpe <[email protected]> wrote on 02/11/2016
01:12:08 PM:
>
> On Thu, Feb 11, 2016 at 10:24:18AM -0500, Stefan Berger wrote:
> > We need two steps here. One to let tpmm_chip_alloc call two
functions
> > tpm_chip_alloc + tpmm_chip_dev (better name?), which are both going
to
> > be public and called by tpm-vtpm.c, and provide tpm_chip_free. Let
me
> > do that. Then we can get rid of the bitmap for the chip->dev_num
> > independently and use idr there.
>
> Make sense. Don't change the names all the drivers would have to be
> churn'd. tpm_chip_alloc, tpmm_chip_alloc.
>
That's right:
struct tpm_chip *tpmm_chip_alloc(struct device *dev,
const struct tpm_class_ops *ops)
{
struct tpm_chip *chip;
chip = tpm_chip_alloc(ops);
if (IS_ERR(chip))
return chip;
tpmm_chip_dev(chip, dev);
return chip;
}
EXPORT_SYMBOL_GPL(tpmm_chip_alloc);
> It is probably OK just to use put_device(&chip->dev), tpm_chip_put is
> already taken for something else. Don't call it free, it isn't free.
tpm_chip_free undoes what tpm_chip_alloc did.
/**
* tpm_chip_alloc() - allocate a new struct tpm_chip instance
* @dev: device to which the chip is associated
* @ops: struct tpm_class_ops instance
*
* Allocates a new struct tpm_chip instance and assigns a free
* device number for it.
*/
struct tpm_chip *tpm_chip_alloc(const struct tpm_class_ops *ops)
{
struct tpm_chip *chip;
chip = kzalloc(sizeof(*chip), GFP_KERNEL);
if (chip == NULL)
return ERR_PTR(-ENOMEM);
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) {
pr_err("No available tpm device numbers\n");
kfree(chip);
return ERR_PTR(-ENOMEM);
}
scnprintf(chip->devname, sizeof(chip->devname), "tpm%d",
chip->dev_num);
return chip;
}
EXPORT_SYMBOL_GPL(tpm_chip_alloc);
/**
* tpm_chip_free() - free tpm_chip previously allocated with
tpm_chip_alloc
* @chip: the tpm_chip to free
*/
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);
Good?
Stefan
>
> 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
_______________________________________________
tpmdd-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tpmdd-devel