Re: [PATCH 4.19 001/106] tpm: use tpm_try_get_ops() in tpm-sysfs.c.
From: Pavel Machek
Date: Tue Oct 08 2019 - 08:51:25 EST
On Sun 2019-10-06 19:20:07, Greg Kroah-Hartman wrote:
> From: Jarkko Sakkinen <jarkko.sakkinen@xxxxxxxxxxxxxxx>
>
> commit 2677ca98ae377517930c183248221f69f771c921 upstream
>
> Use tpm_try_get_ops() in tpm-sysfs.c so that we can consider moving
> other decorations (locking, localities, power management for example)
> inside it. This direction can be of course taken only after other call
> sites for tpm_transmit() have been treated in the same way.
This changes locking completely:
> @@ -244,10 +274,12 @@ static ssize_t cancel_store(struct device *dev, struct device_attribute *attr,
> const char *buf, size_t count)
> {
> struct tpm_chip *chip = to_tpm_chip(dev);
> - if (chip == NULL)
> +
> + if (tpm_try_get_ops(chip))
> return 0;
>
> chip->ops->cancel(chip);
> + tpm_put_ops(chip);
> return count;
> }
> static DEVICE_ATTR_WO(cancel);
For example this did not have any locking, and is now protected by
get_device(&chip->dev);
down_read(&chip->ops_sem);
. Is that intended? Is this known to fix any bugs?
Best regards,
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Attachment:
signature.asc
Description: Digital signature