Re: [PATCH] i2c: busses: Convert parameter to __le32

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Sep 21, 2019 at 10:58:04PM +1000, Adam Zerella wrote:
> The assignment of `serial` is using le32_to_cpu() without
> first converting the parameter `dev->ibuffer` to __le32.
> 
> This produces a Sparse warning of:
> 
> `warning: cast to restricted __le32`
> 
> Signed-off-by: Adam Zerella <adam.zerella@xxxxxxxxx>
> ---
>  drivers/i2c/busses/i2c-diolan-u2c.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
> index 382f105e0fe3..32de47eda950 100644
> --- a/drivers/i2c/busses/i2c-diolan-u2c.c
> +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
> @@ -289,7 +289,7 @@ static void diolan_get_serial(struct i2c_diolan_u2c *dev)
>  
>  	ret = diolan_usb_cmd(dev, CMD_GET_SERIAL, true);
>  	if (ret >= 4) {
> -		serial = le32_to_cpu(*(u32 *)dev->ibuffer);
> +		serial = le32_to_cpu(cpu_to_le32(*(u32 *)dev->ibuffer));

This doesn't make sense. Converting the data from cpu to le32 and
then back to le32 would be a no-op, not a conversion, and the code
would then be wrong on big-endian systems.

Not that it matters much here - it would just display a wrong serial
number. However, if you are making that kind of changes elsewhere to
the kernel, you are trying to mess it up really badly.

Guenter

>  		dev_info(&dev->interface->dev,
>  			 "Diolan U2C serial number %u\n", serial);
>  	}
> -- 
> 2.21.0
> 



[Index of Archives]     [Linux GPIO]     [Linux SPI]     [Linux Hardward Monitoring]     [LM Sensors]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux