[PATCH v2 1/2] iio: pressure: bmp280: Fix type for raw values

Vasileios Amoiridis posted 2 patches 2 months ago
[PATCH v2 1/2] iio: pressure: bmp280: Fix type for raw values
Posted by Vasileios Amoiridis 2 months ago
The adc values coming directly from the sensor in the BM{E,P}{2,3}xx
sensors are unsigned values so treat them as such.

Fixes: 80cd23f43ddc ("iio: pressure: bmp280: Add triggered buffer support")
Signed-off-by: Vasileios Amoiridis <vassilisamir@gmail.com>
---
 drivers/iio/pressure/bmp280-core.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
index 6c2606f34ec4..472a6696303b 100644
--- a/drivers/iio/pressure/bmp280-core.c
+++ b/drivers/iio/pressure/bmp280-core.c
@@ -1023,7 +1023,8 @@ static irqreturn_t bmp280_trigger_handler(int irq, void *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct bmp280_data *data = iio_priv(indio_dev);
-	s32 adc_temp, adc_press, t_fine;
+	u32 adc_temp, adc_press;
+	s32 t_fine;
 	int ret;
 
 	guard(mutex)(&data->lock);
@@ -1137,7 +1138,8 @@ static irqreturn_t bme280_trigger_handler(int irq, void *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct bmp280_data *data = iio_priv(indio_dev);
-	s32 adc_temp, adc_press, adc_humidity, t_fine;
+	u32 adc_temp, adc_press, adc_humidity;
+	s32 t_fine;
 	int ret;
 
 	guard(mutex)(&data->lock);
@@ -1616,7 +1618,8 @@ static irqreturn_t bmp380_trigger_handler(int irq, void *p)
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct bmp280_data *data = iio_priv(indio_dev);
-	s32 adc_temp, adc_press, t_fine;
+	u32 adc_temp, adc_press;
+	s32 t_fine;
 	int ret;
 
 	guard(mutex)(&data->lock);
-- 
2.25.1
Re: [PATCH v2 1/2] iio: pressure: bmp280: Fix type for raw values
Posted by Jonathan Cameron 2 months ago
On Sun, 29 Sep 2024 13:25:10 +0200
Vasileios Amoiridis <vassilisamir@gmail.com> wrote:

> The adc values coming directly from the sensor in the BM{E,P}{2,3}xx
> sensors are unsigned values so treat them as such.
> 
> Fixes: 80cd23f43ddc ("iio: pressure: bmp280: Add triggered buffer support")
Why is this a fix rather than a cleanup?  Looks to me like all the values
are going to be small enough that they fit either way.
So good to tidy up for consistency etc, but why a fixes tag?

I 

> Signed-off-by: Vasileios Amoiridis <vassilisamir@gmail.com>
> ---
>  drivers/iio/pressure/bmp280-core.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
> index 6c2606f34ec4..472a6696303b 100644
> --- a/drivers/iio/pressure/bmp280-core.c
> +++ b/drivers/iio/pressure/bmp280-core.c
> @@ -1023,7 +1023,8 @@ static irqreturn_t bmp280_trigger_handler(int irq, void *p)
>  	struct iio_poll_func *pf = p;
>  	struct iio_dev *indio_dev = pf->indio_dev;
>  	struct bmp280_data *data = iio_priv(indio_dev);
> -	s32 adc_temp, adc_press, t_fine;
> +	u32 adc_temp, adc_press;
These are filled as part of a get_unaligned_be24() so the value will never
be big enough that signed / unsigned should make any difference.

> +	s32 t_fine;
>  	int ret;
>  
>  	guard(mutex)(&data->lock);
> @@ -1137,7 +1138,8 @@ static irqreturn_t bme280_trigger_handler(int irq, void *p)
>  	struct iio_poll_func *pf = p;
>  	struct iio_dev *indio_dev = pf->indio_dev;
>  	struct bmp280_data *data = iio_priv(indio_dev);
> -	s32 adc_temp, adc_press, adc_humidity, t_fine;
> +	u32 adc_temp, adc_press, adc_humidity;
Same with these.
> +	s32 t_fine;
>  	int ret;
>  
>  	guard(mutex)(&data->lock);
> @@ -1616,7 +1618,8 @@ static irqreturn_t bmp380_trigger_handler(int irq, void *p)
>  	struct iio_poll_func *pf = p;
>  	struct iio_dev *indio_dev = pf->indio_dev;
>  	struct bmp280_data *data = iio_priv(indio_dev);
> -	s32 adc_temp, adc_press, t_fine;
These are similar but le24.

> +	u32 adc_temp, adc_press;
> +	s32 t_fine;
>  	int ret;
>  
>  	guard(mutex)(&data->lock);
Re: [PATCH v2 1/2] iio: pressure: bmp280: Fix type for raw values
Posted by Vasileios Amoiridis 2 months ago
On Sun, Sep 29, 2024 at 06:04:26PM +0100, Jonathan Cameron wrote:
> On Sun, 29 Sep 2024 13:25:10 +0200
> Vasileios Amoiridis <vassilisamir@gmail.com> wrote:
> 
> > The adc values coming directly from the sensor in the BM{E,P}{2,3}xx
> > sensors are unsigned values so treat them as such.
> > 
> > Fixes: 80cd23f43ddc ("iio: pressure: bmp280: Add triggered buffer support")
> Why is this a fix rather than a cleanup?  Looks to me like all the values
> are going to be small enough that they fit either way.
> So good to tidy up for consistency etc, but why a fixes tag?
> 
> I 
> 

Hi Jonathan,

I used the fixes tag because I though it was appropriate since it was
using a wrong variable type even though it was not posing any
functional thread (I mentioned it in the cover-letter as well).

Since I am doing a new version I can drop the tag, no problem!!!

Cheers,
Vasilis

> > Signed-off-by: Vasileios Amoiridis <vassilisamir@gmail.com>
> > ---
> >  drivers/iio/pressure/bmp280-core.c | 9 ++++++---
> >  1 file changed, 6 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
> > index 6c2606f34ec4..472a6696303b 100644
> > --- a/drivers/iio/pressure/bmp280-core.c
> > +++ b/drivers/iio/pressure/bmp280-core.c
> > @@ -1023,7 +1023,8 @@ static irqreturn_t bmp280_trigger_handler(int irq, void *p)
> >  	struct iio_poll_func *pf = p;
> >  	struct iio_dev *indio_dev = pf->indio_dev;
> >  	struct bmp280_data *data = iio_priv(indio_dev);
> > -	s32 adc_temp, adc_press, t_fine;
> > +	u32 adc_temp, adc_press;
> These are filled as part of a get_unaligned_be24() so the value will never
> be big enough that signed / unsigned should make any difference.
> 
> > +	s32 t_fine;
> >  	int ret;
> >  
> >  	guard(mutex)(&data->lock);
> > @@ -1137,7 +1138,8 @@ static irqreturn_t bme280_trigger_handler(int irq, void *p)
> >  	struct iio_poll_func *pf = p;
> >  	struct iio_dev *indio_dev = pf->indio_dev;
> >  	struct bmp280_data *data = iio_priv(indio_dev);
> > -	s32 adc_temp, adc_press, adc_humidity, t_fine;
> > +	u32 adc_temp, adc_press, adc_humidity;
> Same with these.
> > +	s32 t_fine;
> >  	int ret;
> >  
> >  	guard(mutex)(&data->lock);
> > @@ -1616,7 +1618,8 @@ static irqreturn_t bmp380_trigger_handler(int irq, void *p)
> >  	struct iio_poll_func *pf = p;
> >  	struct iio_dev *indio_dev = pf->indio_dev;
> >  	struct bmp280_data *data = iio_priv(indio_dev);
> > -	s32 adc_temp, adc_press, t_fine;
> These are similar but le24.
> 
> > +	u32 adc_temp, adc_press;
> > +	s32 t_fine;
> >  	int ret;
> >  
> >  	guard(mutex)(&data->lock);
>