Re: [PATCH] iio: pressure: bmp280: Fix BMP580 temperature reading

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

 



On Thu, 2024-04-25 at 01:22 -0500, Adam Rizkalla wrote:
> Fix overflow issue when storing BMP580 temperature reading and
> properly preserve sign of 24-bit data.
> 
> Signed-off-by: Adam Rizkalla <ajarizzo@xxxxxxxxx>
> ---
>  drivers/iio/pressure/bmp280-core.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-
> core.c
> index fe8734468ed3..e79c9715bb28 100644
> --- a/drivers/iio/pressure/bmp280-core.c
> +++ b/drivers/iio/pressure/bmp280-core.c
> @@ -1393,12 +1393,12 @@ static int bmp580_read_temp(struct bmp280_data *data,
> int *val, int *val2)
>  
>  	/*
>  	 * Temperature is returned in Celsius degrees in fractional
> -	 * form down 2^16. We rescale by x1000 to return milli Celsius
> -	 * to respect IIO ABI.
> +	 * form down 2^16. We rescale by x1000 to return millidegrees
> +	 * Celsius to respect IIO ABI.
>  	 */
> -	*val = raw_temp * 1000;
> -	*val2 = 16;
> -	return IIO_VAL_FRACTIONAL_LOG2;
> +	raw_temp = sign_extend32(raw_temp, 23);
> +	*val = ((s64)raw_temp * 1000) / (1 << 16);
> +	return IIO_VAL_INT;
>  }
>  
>  static int bmp580_read_press(struct bmp280_data *data, int *val, int *val2)

Hi Adam,

Great catch! Reading back the device's datasheet, it also says the raw pressure
value it's a 24 bit signed integer, so we have the same problem on
bmp580_read_press. Could you make a v2 version of this series including the
pressure fix?

Kind regards,
Angel






[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux