Skip to content

Commit 83e7e5d

Browse files
ccpalexjarkkojs
authored andcommitted
tpm: tis_i2c: Limit write bursts to I2C_SMBUS_BLOCK_MAX (32) bytes
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: bbc23a0 ("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> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
1 parent f3b70b6 commit 83e7e5d

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

drivers/char/tpm/tpm_tis_i2c.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,19 +230,27 @@ static int tpm_tis_i2c_write_bytes(struct tpm_tis_data *data, u32 addr, u16 len,
230230
struct i2c_msg msg = { .addr = phy->i2c_client->addr };
231231
u8 reg = tpm_tis_i2c_address_to_register(addr);
232232
int ret;
233+
u16 wrote = 0;
233234

234235
if (len > TPM_BUFSIZE - 1)
235236
return -EIO;
236237

237-
/* write register and data in one go */
238238
phy->io_buf[0] = reg;
239-
memcpy(phy->io_buf + sizeof(reg), value, len);
240-
241-
msg.len = sizeof(reg) + len;
242239
msg.buf = phy->io_buf;
243-
ret = tpm_tis_i2c_retry_transfer_until_ack(data, &msg);
244-
if (ret < 0)
245-
return ret;
240+
while (wrote < len) {
241+
/* write register and data in one go */
242+
msg.len = sizeof(reg) + len - wrote;
243+
if (msg.len > I2C_SMBUS_BLOCK_MAX)
244+
msg.len = I2C_SMBUS_BLOCK_MAX;
245+
246+
memcpy(phy->io_buf + sizeof(reg), value + wrote,
247+
msg.len - sizeof(reg));
248+
249+
ret = tpm_tis_i2c_retry_transfer_until_ack(data, &msg);
250+
if (ret < 0)
251+
return ret;
252+
wrote += msg.len - sizeof(reg);
253+
}
246254

247255
return 0;
248256
}

0 commit comments

Comments
 (0)