mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: Jerry Snitselaar <jsnitsel@redhat.com>
Cc: tpmdd-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org,
	Christophe Ricard <christophe.ricard@gmail.com>,
	Jason Gunthorpe <jgunthorpe@obsidianresearch.com>,
	Marcel Selhorst <tpmdd@selhorst.net>,
	Peter Huewe <peterhuewe@gmx.de>
Subject: Re: [PATCH] tpm: make check_locality return bool
Date: Wed, 22 Mar 2017 09:35:43 +0200	[thread overview]
Message-ID: <20170322073543.a5nqocmd7ddhsy3j@intel.com> (raw)
In-Reply-To: <20170318085957.12277-1-jsnitsel@redhat.com>

On Sat, Mar 18, 2017 at 01:59:57AM -0700, Jerry Snitselaar wrote:
> Since check_locality is checking to see if a certain
> locality is active, return true if active otherwise
> return false.
> 
> Cc: Christophe Ricard <christophe.ricard@gmail.com>
> Cc: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
> Cc: Marcel Selhorst <tpmdd@selhorst.net>
> Cc: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> Cc: Peter Huewe <peterhuewe@gmx.de>
> Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
> ---
> Tested tpm_tis, but don't have the ability to
> test Infineon or STMicro drivers.

Does not matter as this one does not have connection to the used
hardware. I'll have to test this.

/Jarkko

> 
>  drivers/char/tpm/st33zp24/st33zp24.c | 12 ++++++------
>  drivers/char/tpm/tpm_i2c_infineon.c  | 12 ++++++------
>  drivers/char/tpm/tpm_tis_core.c      | 20 +++++++++++---------
>  3 files changed, 23 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/char/tpm/st33zp24/st33zp24.c b/drivers/char/tpm/st33zp24/st33zp24.c
> index e8e0f7c02686..4d1dc8b46877 100644
> --- a/drivers/char/tpm/st33zp24/st33zp24.c
> +++ b/drivers/char/tpm/st33zp24/st33zp24.c
> @@ -117,9 +117,9 @@ static u8 st33zp24_status(struct tpm_chip *chip)
>  /*
>   * check_locality if the locality is active
>   * @param: chip, the tpm chip description
> - * @return: the active locality or -EACCESS.
> + * @return: true if LOCALITY0 is active, otherwise false
>   */
> -static int check_locality(struct tpm_chip *chip)
> +static bool check_locality(struct tpm_chip *chip)
>  {
>  	struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
>  	u8 data;
> @@ -129,9 +129,9 @@ static int check_locality(struct tpm_chip *chip)
>  	if (status && (data &
>  		(TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) ==
>  		(TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID))
> -		return tpm_dev->locality;
> +		return true;
>  
> -	return -EACCES;
> +	return false;
>  } /* check_locality() */
>  
>  /*
> @@ -146,7 +146,7 @@ static int request_locality(struct tpm_chip *chip)
>  	long ret;
>  	u8 data;
>  
> -	if (check_locality(chip) == tpm_dev->locality)
> +	if (check_locality(chip))
>  		return tpm_dev->locality;
>  
>  	data = TPM_ACCESS_REQUEST_USE;
> @@ -158,7 +158,7 @@ static int request_locality(struct tpm_chip *chip)
>  
>  	/* Request locality is usually effective after the request */
>  	do {
> -		if (check_locality(chip) >= 0)
> +		if (check_locality(chip))
>  			return tpm_dev->locality;
>  		msleep(TPM_TIMEOUT);
>  	} while (time_before(jiffies, stop));
> diff --git a/drivers/char/tpm/tpm_i2c_infineon.c b/drivers/char/tpm/tpm_i2c_infineon.c
> index 62ee44e57ddc..dc47fa222a26 100644
> --- a/drivers/char/tpm/tpm_i2c_infineon.c
> +++ b/drivers/char/tpm/tpm_i2c_infineon.c
> @@ -278,22 +278,22 @@ enum tis_defaults {
>  #define	TPM_DATA_FIFO(l)		(0x0005 | ((l) << 4))
>  #define	TPM_DID_VID(l)			(0x0006 | ((l) << 4))
>  
> -static int check_locality(struct tpm_chip *chip, int loc)
> +static bool check_locality(struct tpm_chip *chip, int loc)
>  {
>  	u8 buf;
>  	int rc;
>  
>  	rc = iic_tpm_read(TPM_ACCESS(loc), &buf, 1);
>  	if (rc < 0)
> -		return rc;
> +		return false;
>  
>  	if ((buf & (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) ==
>  	    (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) {
>  		tpm_dev.locality = loc;
> -		return loc;
> +		return true;
>  	}
>  
> -	return -EIO;
> +	return false;
>  }
>  
>  /* implementation similar to tpm_tis */
> @@ -315,7 +315,7 @@ static int request_locality(struct tpm_chip *chip, int loc)
>  	unsigned long stop;
>  	u8 buf = TPM_ACCESS_REQUEST_USE;
>  
> -	if (check_locality(chip, loc) >= 0)
> +	if (check_locality(chip, loc))
>  		return loc;
>  
>  	iic_tpm_write(TPM_ACCESS(loc), &buf, 1);
> @@ -323,7 +323,7 @@ static int request_locality(struct tpm_chip *chip, int loc)
>  	/* wait for burstcount */
>  	stop = jiffies + chip->timeout_a;
>  	do {
> -		if (check_locality(chip, loc) >= 0)
> +		if (check_locality(chip, loc))
>  			return loc;
>  		usleep_range(TPM_TIMEOUT_US_LOW, TPM_TIMEOUT_US_HI);
>  	} while (time_before(jiffies, stop));
> diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
> index c0f296b5d413..93d641996249 100644
> --- a/drivers/char/tpm/tpm_tis_core.c
> +++ b/drivers/char/tpm/tpm_tis_core.c
> @@ -56,7 +56,7 @@ static int wait_startup(struct tpm_chip *chip, int l)
>  	return -1;
>  }
>  
> -static int check_locality(struct tpm_chip *chip, int l)
> +static bool check_locality(struct tpm_chip *chip, int l)
>  {
>  	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
>  	int rc;
> @@ -64,13 +64,15 @@ static int check_locality(struct tpm_chip *chip, int l)
>  
>  	rc = tpm_tis_read8(priv, TPM_ACCESS(l), &access);
>  	if (rc < 0)
> -		return rc;
> +		return false;
>  
>  	if ((access & (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) ==
> -	    (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID))
> -		return priv->locality = l;
> +	    (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) {
> +		priv->locality = l;
> +		return true;
> +	}
>  
> -	return -1;
> +	return false;
>  }
>  
>  static void release_locality(struct tpm_chip *chip, int l, int force)
> @@ -96,7 +98,7 @@ static int request_locality(struct tpm_chip *chip, int l)
>  	unsigned long stop, timeout;
>  	long rc;
>  
> -	if (check_locality(chip, l) >= 0)
> +	if (check_locality(chip, l))
>  		return l;
>  
>  	rc = tpm_tis_write8(priv, TPM_ACCESS(l), TPM_ACCESS_REQUEST_USE);
> @@ -112,7 +114,7 @@ static int request_locality(struct tpm_chip *chip, int l)
>  			return -1;
>  		rc = wait_event_interruptible_timeout(priv->int_queue,
>  						      (check_locality
> -						       (chip, l) >= 0),
> +						       (chip, l)),
>  						      timeout);
>  		if (rc > 0)
>  			return l;
> @@ -123,7 +125,7 @@ static int request_locality(struct tpm_chip *chip, int l)
>  	} else {
>  		/* wait for burstcount */
>  		do {
> -			if (check_locality(chip, l) >= 0)
> +			if (check_locality(chip, l))
>  				return l;
>  			msleep(TPM_TIMEOUT);
>  		} while (time_before(jiffies, stop));
> @@ -533,7 +535,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id)
>  		wake_up_interruptible(&priv->read_queue);
>  	if (interrupt & TPM_INTF_LOCALITY_CHANGE_INT)
>  		for (i = 0; i < 5; i++)
> -			if (check_locality(chip, i) >= 0)
> +			if (check_locality(chip, i))
>  				break;
>  	if (interrupt &
>  	    (TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_STS_VALID_INT |
> -- 
> 2.12.0.399.g9d77b0405ce6
> 

  reply	other threads:[~2017-03-22  7:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-18  8:59 Jerry Snitselaar
2017-03-22  7:35 ` Jarkko Sakkinen [this message]
2017-03-22 11:24 ` Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170322073543.a5nqocmd7ddhsy3j@intel.com \
    --to=jarkko.sakkinen@linux.intel.com \
    --cc=christophe.ricard@gmail.com \
    --cc=jgunthorpe@obsidianresearch.com \
    --cc=jsnitsel@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterhuewe@gmx.de \
    --cc=tpmdd-devel@lists.sourceforge.net \
    --cc=tpmdd@selhorst.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®