Linux Integrity Measurement development
 help / color / mirror / Atom feed
From: "Jarkko Sakkinen" <jarkko@kernel.org>
To: "A. Sverdlin" <alexander.sverdlin@siemens.com>,
	<linux-integrity@vger.kernel.org>
Cc: "Peter Huewe" <peterhuewe@gmx.de>,
	"Jason Gunthorpe" <jgg@ziepe.ca>, <linux-kernel@vger.kernel.org>,
	"Alexander Steffen" <Alexander.Steffen@infineon.com>,
	"Michael Haener" <michael.haener@siemens.com>
Subject: Re: [PATCH 2/2] tpm: tis_i2c: Limit write bursts to I2C_SMBUS_BLOCK_MAX (32) bytes
Date: Wed, 07 Jun 2023 00:24:28 +0300	[thread overview]
Message-ID: <CT5VUA5ZPSD3.6H4DN11M7148@suppilovahvero> (raw)
In-Reply-To: <20230524154040.1204030-2-alexander.sverdlin@siemens.com>

On Wed May 24, 2023 at 6:40 PM EEST, A. Sverdlin wrote:
> From: Alexander Sverdlin <alexander.sverdlin@siemens.com>
>
> Underlying I2C bus drivers not always support longer transfers and
> imx-lpi2c for instance doesn't. The fix is symmetric to previous patch
> which fixed the read direction.
>

Cc: stable@vger.kernel.org # v5.20+

> Fixes: bbc23a07b072 ("tpm: Add tpm_tis_i2c backend for tpm_tis_core")
> Tested-by: Michael Haener <michael.haener@siemens.com>
> Signed-off-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
> ---
>  drivers/char/tpm/tpm_tis_i2c.c | 22 +++++++++++++++-------
>  1 file changed, 15 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm_tis_i2c.c b/drivers/char/tpm/tpm_tis_i2c.c
> index 106fd20d94e4..82fda488e98b 100644
> --- a/drivers/char/tpm/tpm_tis_i2c.c
> +++ b/drivers/char/tpm/tpm_tis_i2c.c
> @@ -230,19 +230,27 @@ static int tpm_tis_i2c_write_bytes(struct tpm_tis_data *data, u32 addr, u16 len,
>  	struct i2c_msg msg = { .addr = phy->i2c_client->addr };
>  	u8 reg = tpm_tis_i2c_address_to_register(addr);
>  	int ret;
> +	u16 wrote = 0;
>  
>  	if (len > TPM_BUFSIZE - 1)
>  		return -EIO;
>  
> -	/* write register and data in one go */
>  	phy->io_buf[0] = reg;
> -	memcpy(phy->io_buf + sizeof(reg), value, len);
> -
> -	msg.len = sizeof(reg) + len;
>  	msg.buf = phy->io_buf;
> -	ret = tpm_tis_i2c_retry_transfer_until_ack(data, &msg);
> -	if (ret < 0)
> -		return ret;
> +	while (wrote < len) {
> +		/* write register and data in one go */
> +		msg.len = sizeof(reg) + len - wrote;
> +		if (msg.len > I2C_SMBUS_BLOCK_MAX)
> +			msg.len = I2C_SMBUS_BLOCK_MAX;
> +
> +		memcpy(phy->io_buf + sizeof(reg), value + wrote,
> +		       msg.len - sizeof(reg));
> +
> +		ret = tpm_tis_i2c_retry_transfer_until_ack(data, &msg);
> +		if (ret < 0)
> +			return ret;
> +		wrote += msg.len - sizeof(reg);
> +	}
>  
>  	return 0;
>  }
> -- 
> 2.40.1

Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

BR, Jarkko

  parent reply	other threads:[~2023-06-06 21:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-24 15:40 [PATCH 1/2] tpm: tis_i2c: Limit read bursts to I2C_SMBUS_BLOCK_MAX (32) bytes A. Sverdlin
2023-05-24 15:40 ` [PATCH 2/2] tpm: tis_i2c: Limit write " A. Sverdlin
2023-05-24 22:05   ` Jerry Snitselaar
2023-06-06 21:24   ` Jarkko Sakkinen [this message]
2023-05-24 16:03 ` [PATCH 1/2] tpm: tis_i2c: Limit read " Jarkko Sakkinen
2023-05-24 18:19 ` Jerry Snitselaar
2023-06-06 21:23 ` 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=CT5VUA5ZPSD3.6H4DN11M7148@suppilovahvero \
    --to=jarkko@kernel.org \
    --cc=Alexander.Steffen@infineon.com \
    --cc=alexander.sverdlin@siemens.com \
    --cc=jgg@ziepe.ca \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.haener@siemens.com \
    --cc=peterhuewe@gmx.de \
    /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