linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jean Delvare <jdelvare@suse.de>
To: Heiner Kallweit <hkallweit1@gmail.com>
Cc: linux-i2c@vger.kernel.org
Subject: Re: i2c: i801: Don't silently correct invalid transfer size
Date: Tue, 9 Nov 2021 16:09:30 +0100	[thread overview]
Message-ID: <20211109160930.6f052ff2@endymion> (raw)
In-Reply-To: <a5e9b8b5-82af-96a1-b983-d98c2fa140f9@gmail.com>

Hi Heiner,

On Sun, 07 Nov 2021 22:57:00 +0100, Heiner Kallweit wrote:
> If an invalid block size is provided, reject it instead of silently
> changing it to a supported value. Especially critical I see the case of
> a write transfer with block length 0. In this case we have no guarantee
> that the byte we would write is valid. When silently reducing a read to
> 32 bytes then we don't return an error and the caller may falsely
> assume that we returned the full requested data.
> 
> If this change should break any (broken) caller, then I think we should
> fix the caller.

Fully agreed.

> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>  drivers/i2c/busses/i2c-i801.c | 15 +++++----------
>  1 file changed, 5 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
> index 2c48691d2..638198b4b 100644
> --- a/drivers/i2c/busses/i2c-i801.c
> +++ b/drivers/i2c/busses/i2c-i801.c
> @@ -761,6 +761,11 @@ static int i801_block_transaction(struct i801_priv *priv, union i2c_smbus_data *
>  	int result = 0;
>  	unsigned char hostc;
>  
> +	if (read_write == I2C_SMBUS_READ && command == I2C_SMBUS_BLOCK_DATA)
> +		data->block[0] = I2C_SMBUS_BLOCK_MAX;
> +	else if (data->block[0] < 1 || data->block[0] > I2C_SMBUS_BLOCK_MAX)
> +		return -EPROTO;
> +
>  	if (command == I2C_SMBUS_I2C_BLOCK_DATA) {
>  		if (read_write == I2C_SMBUS_WRITE) {
>  			/* set I2C_EN bit in configuration register */
> @@ -774,16 +779,6 @@ static int i801_block_transaction(struct i801_priv *priv, union i2c_smbus_data *
>  		}
>  	}
>  
> -	if (read_write == I2C_SMBUS_WRITE
> -	 || command == I2C_SMBUS_I2C_BLOCK_DATA) {
> -		if (data->block[0] < 1)
> -			data->block[0] = 1;
> -		if (data->block[0] > I2C_SMBUS_BLOCK_MAX)
> -			data->block[0] = I2C_SMBUS_BLOCK_MAX;
> -	} else {
> -		data->block[0] = 32;	/* max for SMBus block reads */
> -	}
> -
>  	/* Experience has shown that the block buffer can only be used for
>  	   SMBus (not I2C) block transactions, even though the datasheet
>  	   doesn't mention this limitation. */

Reviewed-by: Jean Delvare <jdelvare@suse.de>

-- 
Jean Delvare
SUSE L3 Support

  reply	other threads:[~2021-11-09 15:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-07 21:57 i2c: i801: Don't silently correct invalid transfer size Heiner Kallweit
2021-11-09 15:09 ` Jean Delvare [this message]
2021-11-29  8:54 ` Wolfram Sang

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=20211109160930.6f052ff2@endymion \
    --to=jdelvare@suse.de \
    --cc=hkallweit1@gmail.com \
    --cc=linux-i2c@vger.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;
as well as URLs for NNTP newsgroup(s).