lkml.org 
[lkml]   [2022]   [Jul]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    Date
    SubjectRe: [PATCH v7 07/10] tmp, tmp_tis: Implement usage counter for locality
    Hi,

    This patch subject has a typo "tmp, tmp_tis" -> "tpm, tpm_tis"

    On Wed, Jun 29, 2022 at 7:28 PM Lino Sanfilippo <LinoSanfilippo@gmx.de> wrote:
    >
    > From: Lino Sanfilippo <l.sanfilippo@kunbus.com>
    >
    > Implement a usage counter for the (default) locality used by the TPM TIS
    > driver:
    > Request the locality from the TPM if it has not been claimed yet, otherwise
    > only increment the counter. Also release the locality if the counter is 0
    > otherwise only decrement the counter. Ensure thread-safety by protecting
    > the counter with a mutex.
    >
    > This allows to request and release the locality from a thread and the
    > interrupt handler at the same time without the danger to interfere with
    > each other.
    >
    > By doing this refactor the names of the amended functions to use the proper
    > prefix.
    >
    > Signed-off-by: Lino Sanfilippo <l.sanfilippo@kunbus.com>
    > Tested-by: Michael Niewöhner <linux@mniewoehner.de>
    > ---
    > drivers/char/tpm/tpm_tis_core.c | 75 ++++++++++++++++++++++-----------
    > drivers/char/tpm/tpm_tis_core.h | 2 +
    > 2 files changed, 53 insertions(+), 24 deletions(-)
    >
    > diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
    > index bd4eeb0b2192..e50a2c78de9f 100644
    > --- a/drivers/char/tpm/tpm_tis_core.c
    > +++ b/drivers/char/tpm/tpm_tis_core.c

    > @@ -215,6 +226,20 @@ static int request_locality(struct tpm_chip *chip, int l)
    > return -1;
    > }
    >
    > +static int tpm_tis_request_locality(struct tpm_chip *chip, int l)
    > +{
    > + struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
    > + int ret = 0;
    > +
    > + mutex_lock(&priv->locality_count_mutex);
    > + if (priv->locality_count == 0)
    > + ret = tpm_tis_request_locality_locked(chip, l);
    > + if (!ret)
    > + priv->locality_count++;
    > + mutex_unlock(&priv->locality_count_mutex);
    > + return ret;
    > +}
    > +

    This function should check that the requested locality matches the
    current locality otherwise this sequence would seemingly succeed
    though locality 0 is the one acquired.

    tpm_tis_request_locality(chip, 0);
    tpm_tis_request_locality(chip, 1);

    Regards,
    Jason

    \
     
     \ /
      Last update: 2022-07-11 21:40    [W:3.306 / U:0.800 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site