This is a note to let you know that I've just added the patch titled i2c: i801: fix potential race in i801_block_transaction_byte_by_byte to the 5.15-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: i2c-i801-fix-potential-race-in-i801_block_transaction_byte_by_byte.patch and it can be found in the queue-5.15 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From f78ca48a8ba9cdec96e8839351e49eec3233b177 Mon Sep 17 00:00:00 2001 From: Heiner Kallweit <hkallweit1@xxxxxxxxx> Date: Sat, 9 Sep 2023 22:25:06 +0200 Subject: i2c: i801: fix potential race in i801_block_transaction_byte_by_byte From: Heiner Kallweit <hkallweit1@xxxxxxxxx> commit f78ca48a8ba9cdec96e8839351e49eec3233b177 upstream. 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@xxxxxxxx> Closes: https://lore.kernel.org/linux-i2c/20230828152747.09444625@endymion.delvare/ Cc: stable@xxxxxxxxxxxxxxx Acked-by: Andi Shyti <andi.shyti@xxxxxxxxxx> Signed-off-by: Heiner Kallweit <hkallweit1@xxxxxxxxx> Reviewed-by: Jean Delvare <jdelvare@xxxxxxx> Signed-off-by: Wolfram Sang <wsa@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/i2c/busses/i2c-i801.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c @@ -702,15 +702,11 @@ static int i801_block_transaction_byte_b return i801_check_post(priv, result ? priv->status : -ETIMEDOUT); } - for (i = 1; i <= len; i++) { - if (i == len && read_write == I2C_SMBUS_READ) - smbcmd |= SMBHSTCNT_LAST_BYTE; - outb_p(smbcmd, SMBHSTCNT(priv)); - - if (i == 1) - outb_p(inb(SMBHSTCNT(priv)) | SMBHSTCNT_START, - SMBHSTCNT(priv)); + if (len == 1 && read_write == I2C_SMBUS_READ) + smbcmd |= SMBHSTCNT_LAST_BYTE; + outb_p(smbcmd | SMBHSTCNT_START, SMBHSTCNT(priv)); + for (i = 1; i <= len; i++) { status = i801_wait_byte_done(priv); if (status) goto exit; @@ -733,9 +729,12 @@ static int i801_block_transaction_byte_b data->block[0] = len; } - /* Retrieve/store value in SMBBLKDAT */ - if (read_write == I2C_SMBUS_READ) + if (read_write == I2C_SMBUS_READ) { data->block[i] = inb_p(SMBBLKDAT(priv)); + if (i == len - 1) + outb_p(smbcmd | SMBHSTCNT_LAST_BYTE, SMBHSTCNT(priv)); + } + if (read_write == I2C_SMBUS_WRITE && i+1 <= len) outb_p(data->block[i+1], SMBBLKDAT(priv)); Patches currently in stable-queue which might be from hkallweit1@xxxxxxxxx are queue-5.15/i2c-i801-fix-potential-race-in-i801_block_transaction_byte_by_byte.patch queue-5.15/pci-aspm-fix-l1-substate-handling-in-aspm_attr_store_common.patch