Skip to content

Commit 5417834

Browse files
committed
i2c: i801: fix potential race in i801_block_transaction_byte_by_byte
JIRA: https://issues.redhat.com/browse/RHEL-47426 commit f78ca48 Author: Heiner Kallweit <hkallweit1@gmail.com> Date: Sat Sep 9 22:25:06 2023 +0200 i2c: i801: fix potential race in i801_block_transaction_byte_by_byte Currently we set SMBHSTCNT_LAST_BYTE only after the host has started receiving the last byte. If we get e.g. preempted before setting SMBHSTCNT_LAST_BYTE, the host may be finished with receiving the byte before SMBHSTCNT_LAST_BYTE is set. Therefore change the code to set SMBHSTCNT_LAST_BYTE before writing SMBHSTSTS_BYTE_DONE for the byte before the last byte. Now the code is also consistent with what we do in i801_isr_byte_done(). Reported-by: Jean Delvare <jdelvare@suse.com> Closes: https://lore.kernel.org/linux-i2c/20230828152747.09444625@endymion.delvare/ Cc: stable@vger.kernel.org Acked-by: Andi Shyti <andi.shyti@kernel.org> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Reviewed-by: Jean Delvare <jdelvare@suse.de> Signed-off-by: Wolfram Sang <wsa@kernel.org> Signed-off-by: David Arcari <darcari@redhat.com>
1 parent bf493c1 commit 5417834

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

drivers/i2c/busses/i2c-i801.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -708,15 +708,11 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
708708
return result ? priv->status : -ETIMEDOUT;
709709
}
710710

711-
for (i = 1; i <= len; i++) {
712-
if (i == len && read_write == I2C_SMBUS_READ)
713-
smbcmd |= SMBHSTCNT_LAST_BYTE;
714-
outb_p(smbcmd, SMBHSTCNT(priv));
715-
716-
if (i == 1)
717-
outb_p(inb(SMBHSTCNT(priv)) | SMBHSTCNT_START,
718-
SMBHSTCNT(priv));
711+
if (len == 1 && read_write == I2C_SMBUS_READ)
712+
smbcmd |= SMBHSTCNT_LAST_BYTE;
713+
outb_p(smbcmd | SMBHSTCNT_START, SMBHSTCNT(priv));
719714

715+
for (i = 1; i <= len; i++) {
720716
status = i801_wait_byte_done(priv);
721717
if (status)
722718
return status;
@@ -740,9 +736,12 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
740736
data->block[0] = len;
741737
}
742738

743-
/* Retrieve/store value in SMBBLKDAT */
744-
if (read_write == I2C_SMBUS_READ)
739+
if (read_write == I2C_SMBUS_READ) {
745740
data->block[i] = inb_p(SMBBLKDAT(priv));
741+
if (i == len - 1)
742+
outb_p(smbcmd | SMBHSTCNT_LAST_BYTE, SMBHSTCNT(priv));
743+
}
744+
746745
if (read_write == I2C_SMBUS_WRITE && i+1 <= len)
747746
outb_p(data->block[i+1], SMBBLKDAT(priv));
748747

0 commit comments

Comments
 (0)