From: Jean Delvare <jdelvare@suse.de>
To: Heiner Kallweit <hkallweit1@gmail.com>
Cc: Wolfram Sang <wsa@kernel.org>, Andi Shyti <andi.shyti@kernel.org>,
linux-i2c@vger.kernel.org
Subject: Re: [PATCH v2] i2c: i801: fix potential race in i801_block_transaction_byte_by_byte
Date: Tue, 5 Sep 2023 10:12:43 +0200 [thread overview]
Message-ID: <20230905101243.39920fe5@endymion.delvare> (raw)
In-Reply-To: <f056286a-1db9-b88c-6d36-a3358190b9c9@gmail.com>
On Sat, 02 Sep 2023 22:10:52 +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>
Note for Wolfram: checkpatch says we should insert here:
Closes: https://lore.kernel.org/linux-i2c/20230828152747.09444625@endymion.delvare/
> Reviewed-by: Jean Delvare <jdelvare@suse.de>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
> v2:
> - remove incorrect 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));
>
--
Jean Delvare
SUSE L3 Support
next prev parent reply other threads:[~2023-09-05 16:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-02 20:10 [PATCH v2] i2c: i801: fix potential race in i801_block_transaction_byte_by_byte Heiner Kallweit
2023-09-05 8:12 ` Jean Delvare [this message]
2023-09-05 9:11 ` Andi Shyti
2023-09-05 11:35 ` Heiner Kallweit
2023-09-05 22:59 ` Andi Shyti
2023-09-06 6:05 ` Heiner Kallweit
2023-09-06 8:50 ` Greg Kroah-Hartman
2023-09-06 8:07 ` Jean Delvare
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=20230905101243.39920fe5@endymion.delvare \
--to=jdelvare@suse.de \
--cc=andi.shyti@kernel.org \
--cc=hkallweit1@gmail.com \
--cc=linux-i2c@vger.kernel.org \
--cc=wsa@kernel.org \
/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