* [PATCH v3] i2c: i801: fix potential race in i801_block_transaction_byte_by_byte
@ 2023-09-09 20:25 Heiner Kallweit
2023-09-13 5:13 ` Jean Delvare
2023-09-19 8:58 ` Wolfram Sang
0 siblings, 2 replies; 3+ messages in thread
From: Heiner Kallweit @ 2023-09-09 20:25 UTC (permalink / raw)
To: Jean Delvare, Andi Shyti; +Cc: linux-i2c@vger.kernel.org
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>
---
v3:
- Apparently potential issue has been there forever, therefore cc
to stable w/o Fixes tag.
---
drivers/i2c/busses/i2c-i801.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 7a0ccc584..8acf09539 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -679,15 +679,11 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
return 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)
return status;
@@ -710,9 +706,12 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
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));
--
2.42.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v3] i2c: i801: fix potential race in i801_block_transaction_byte_by_byte
2023-09-09 20:25 [PATCH v3] i2c: i801: fix potential race in i801_block_transaction_byte_by_byte Heiner Kallweit
@ 2023-09-13 5:13 ` Jean Delvare
2023-09-19 8:58 ` Wolfram Sang
1 sibling, 0 replies; 3+ messages in thread
From: Jean Delvare @ 2023-09-13 5:13 UTC (permalink / raw)
To: Heiner Kallweit; +Cc: Andi Shyti, linux-i2c
On Sat, 09 Sep 2023 22:25:06 +0200, Heiner Kallweit wrote:
> 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>
--
Jean Delvare
SUSE L3 Support
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] i2c: i801: fix potential race in i801_block_transaction_byte_by_byte
2023-09-09 20:25 [PATCH v3] i2c: i801: fix potential race in i801_block_transaction_byte_by_byte Heiner Kallweit
2023-09-13 5:13 ` Jean Delvare
@ 2023-09-19 8:58 ` Wolfram Sang
1 sibling, 0 replies; 3+ messages in thread
From: Wolfram Sang @ 2023-09-19 8:58 UTC (permalink / raw)
To: Heiner Kallweit; +Cc: Jean Delvare, Andi Shyti, linux-i2c@vger.kernel.org
[-- Attachment #1: Type: text/plain, Size: 831 bytes --]
On Sat, Sep 09, 2023 at 10:25:06PM +0200, Heiner Kallweit wrote:
> 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>
Applied to for-next, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-09-19 8:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-09 20:25 [PATCH v3] i2c: i801: fix potential race in i801_block_transaction_byte_by_byte Heiner Kallweit
2023-09-13 5:13 ` Jean Delvare
2023-09-19 8:58 ` Wolfram Sang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox