linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: imu: inv_mpu6050: check for temp_fifo_enable
@ 2020-08-09 15:59 trix
  2020-08-10  8:02 ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: trix @ 2020-08-09 15:59 UTC (permalink / raw)
  To: jic23, knaack.h, lars, pmeerw, jmaneyrol, mirq-linux, lee.jones
  Cc: linux-iio, linux-kernel, Tom Rix

From: Tom Rix <trix@redhat.com>

clang static analysis reports this problem

inv_mpu_ring.c:181:18: warning: Division by zero
        nb = fifo_count / bytes_per_datum;
             ~~~~~~~~~~~^~~~~~~~~~~~~~~~~

This is a false positive.
Dividing by 0 is protected by this check

	if (!(st->chip_config.accl_fifo_enable |
		st->chip_config.gyro_fifo_enable |
		st->chip_config.magn_fifo_enable))
		goto end_session;
	bytes_per_datum = 0;

But there is another fifo, temp_fifo

	if (st->chip_config.temp_fifo_enable)
		bytes_per_datum += INV_MPU6050_BYTES_PER_TEMP_SENSOR;

Which would be skipped if it was the only enabled fifo.
So add to the check.

Fixes: 2e4c0a5e2576 ("iio: imu: inv_mpu6050: add fifo temperature data support")

Signed-off-by: Tom Rix <trix@redhat.com>
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
index b533fa2dad0a..5240a400dcb4 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
@@ -141,6 +141,7 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)
 
 	if (!(st->chip_config.accl_fifo_enable |
 		st->chip_config.gyro_fifo_enable |
+		st->chip_config.temp_fifo_enable |
 		st->chip_config.magn_fifo_enable))
 		goto end_session;
 	bytes_per_datum = 0;
-- 
2.18.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: imu: inv_mpu6050: check for temp_fifo_enable
  2020-08-09 15:59 [PATCH] iio: imu: inv_mpu6050: check for temp_fifo_enable trix
@ 2020-08-10  8:02 ` Andy Shevchenko
  2020-08-13  8:04   ` Jean-Baptiste Maneyrol
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2020-08-10  8:02 UTC (permalink / raw)
  To: trix
  Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald, Jean-Baptiste Maneyrol,
	Michał Mirosław, Lee Jones, linux-iio,
	Linux Kernel Mailing List

On Sun, Aug 9, 2020 at 7:00 PM <trix@redhat.com> wrote:
>
> From: Tom Rix <trix@redhat.com>
>
> clang static analysis reports this problem
>
> inv_mpu_ring.c:181:18: warning: Division by zero
>         nb = fifo_count / bytes_per_datum;
>              ~~~~~~~~~~~^~~~~~~~~~~~~~~~~
>
> This is a false positive.
> Dividing by 0 is protected by this check
>
>         if (!(st->chip_config.accl_fifo_enable |
>                 st->chip_config.gyro_fifo_enable |
>                 st->chip_config.magn_fifo_enable))
>                 goto end_session;
>         bytes_per_datum = 0;
>
> But there is another fifo, temp_fifo
>
>         if (st->chip_config.temp_fifo_enable)
>                 bytes_per_datum += INV_MPU6050_BYTES_PER_TEMP_SENSOR;
>
> Which would be skipped if it was the only enabled fifo.
> So add to the check.
>

> Fixes: 2e4c0a5e2576 ("iio: imu: inv_mpu6050: add fifo temperature data support")
>
> Signed-off-by: Tom Rix <trix@redhat.com>

There shouldn't be a blank line in between.

Other than that,
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>



> ---
>  drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
> index b533fa2dad0a..5240a400dcb4 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
> @@ -141,6 +141,7 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)
>
>         if (!(st->chip_config.accl_fifo_enable |
>                 st->chip_config.gyro_fifo_enable |
> +               st->chip_config.temp_fifo_enable |
>                 st->chip_config.magn_fifo_enable))
>                 goto end_session;
>         bytes_per_datum = 0;
> --
> 2.18.1
>


--
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: imu: inv_mpu6050: check for temp_fifo_enable
  2020-08-10  8:02 ` Andy Shevchenko
@ 2020-08-13  8:04   ` Jean-Baptiste Maneyrol
  2020-08-16  8:58     ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Jean-Baptiste Maneyrol @ 2020-08-13  8:04 UTC (permalink / raw)
  To: Andy Shevchenko, trix
  Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald, Michał Mirosław, Lee Jones, linux-iio,
	Linux Kernel Mailing List

Hello,

this is a case that should never be happening since available scan mask only advertise Accel + Temp, Gyro + Temp, or Accel + Gyro + Temp.
More than that, temperature sensor is not working when MEMS engine is off. (it's only purpose it to measure temperature of the MEMS to do data temperature compensation).

So I think we can let this check as it is currently, since this is not a supported configuration.

Best regards,
JB


From: Andy Shevchenko <andy.shevchenko@gmail.com>
Sent: Monday, August 10, 2020 10:02
To: trix@redhat.com <trix@redhat.com>
Cc: Jonathan Cameron <jic23@kernel.org>; Hartmut Knaack <knaack.h@gmx.de>; Lars-Peter Clausen <lars@metafoo.de>; Peter Meerwald <pmeerw@pmeerw.net>; Jean-Baptiste Maneyrol <JManeyrol@invensense.com>; Michał Mirosław <mirq-linux@rere.qmqm.pl>; Lee Jones <lee.jones@linaro.org>; linux-iio <linux-iio@vger.kernel.org>; Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] iio: imu: inv_mpu6050: check for temp_fifo_enable 
 
 CAUTION: This email originated from outside of the organization. Please make sure the sender is who they say they are and do not click links or open attachments unless you recognize the sender and know the content is safe.

On Sun, Aug 9, 2020 at 7:00 PM <trix@redhat.com> wrote:
>
> From: Tom Rix <trix@redhat.com>
>
> clang static analysis reports this problem
>
> inv_mpu_ring.c:181:18: warning: Division by zero
>         nb = fifo_count / bytes_per_datum;
>              ~~~~~~~~~~~^~~~~~~~~~~~~~~~~
>
> This is a false positive.
> Dividing by 0 is protected by this check
>
>         if (!(st->chip_config.accl_fifo_enable |
>                 st->chip_config.gyro_fifo_enable |
>                 st->chip_config.magn_fifo_enable))
>                 goto end_session;
>         bytes_per_datum = 0;
>
> But there is another fifo, temp_fifo
>
>         if (st->chip_config.temp_fifo_enable)
>                 bytes_per_datum += INV_MPU6050_BYTES_PER_TEMP_SENSOR;
>
> Which would be skipped if it was the only enabled fifo.
> So add to the check.
>

> Fixes: 2e4c0a5e2576 ("iio: imu: inv_mpu6050: add fifo temperature data support")
>
> Signed-off-by: Tom Rix <trix@redhat.com>

There shouldn't be a blank line in between.

Other than that,
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>



> ---
>  drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
> index b533fa2dad0a..5240a400dcb4 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
> @@ -141,6 +141,7 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)
>
>         if (!(st->chip_config.accl_fifo_enable |
>                 st->chip_config.gyro_fifo_enable |
> +               st->chip_config.temp_fifo_enable |
>                 st->chip_config.magn_fifo_enable))
>                 goto end_session;
>         bytes_per_datum = 0;
> --
> 2.18.1
>


--
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: imu: inv_mpu6050: check for temp_fifo_enable
  2020-08-13  8:04   ` Jean-Baptiste Maneyrol
@ 2020-08-16  8:58     ` Jonathan Cameron
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2020-08-16  8:58 UTC (permalink / raw)
  To: Jean-Baptiste Maneyrol
  Cc: Andy Shevchenko, trix, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald, Michał Mirosław, Lee Jones, linux-iio,
	Linux Kernel Mailing List

On Thu, 13 Aug 2020 08:04:06 +0000
Jean-Baptiste Maneyrol <JManeyrol@invensense.com> wrote:

> Hello,
> 
> this is a case that should never be happening since available scan mask only advertise Accel + Temp, Gyro + Temp, or Accel + Gyro + Temp.
> More than that, temperature sensor is not working when MEMS engine is off. (it's only purpose it to measure temperature of the MEMS to do data temperature compensation).
> 
> So I think we can let this check as it is currently, since this is not a supported configuration.
> 

Perhaps a good option would be to add a suitably positioned comment to make
this clear so we don't get further patches 'fixing' this in the future?

Thanks,

Jonathan

> Best regards,
> JB
> 
> 
> From: Andy Shevchenko <andy.shevchenko@gmail.com>
> Sent: Monday, August 10, 2020 10:02
> To: trix@redhat.com <trix@redhat.com>
> Cc: Jonathan Cameron <jic23@kernel.org>; Hartmut Knaack <knaack.h@gmx.de>; Lars-Peter Clausen <lars@metafoo.de>; Peter Meerwald <pmeerw@pmeerw.net>; Jean-Baptiste Maneyrol <JManeyrol@invensense.com>; Michał Mirosław <mirq-linux@rere.qmqm.pl>; Lee Jones <lee.jones@linaro.org>; linux-iio <linux-iio@vger.kernel.org>; Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
> Subject: Re: [PATCH] iio: imu: inv_mpu6050: check for temp_fifo_enable 
>  
>  CAUTION: This email originated from outside of the organization. Please make sure the sender is who they say they are and do not click links or open attachments unless you recognize the sender and know the content is safe.
> 
> On Sun, Aug 9, 2020 at 7:00 PM <trix@redhat.com> wrote:
> >
> > From: Tom Rix <trix@redhat.com>
> >
> > clang static analysis reports this problem
> >
> > inv_mpu_ring.c:181:18: warning: Division by zero
> >         nb = fifo_count / bytes_per_datum;
> >              ~~~~~~~~~~~^~~~~~~~~~~~~~~~~
> >
> > This is a false positive.
> > Dividing by 0 is protected by this check
> >
> >         if (!(st->chip_config.accl_fifo_enable |
> >                 st->chip_config.gyro_fifo_enable |
> >                 st->chip_config.magn_fifo_enable))
> >                 goto end_session;
> >         bytes_per_datum = 0;
> >
> > But there is another fifo, temp_fifo
> >
> >         if (st->chip_config.temp_fifo_enable)
> >                 bytes_per_datum += INV_MPU6050_BYTES_PER_TEMP_SENSOR;
> >
> > Which would be skipped if it was the only enabled fifo.
> > So add to the check.
> >  
> 
> > Fixes: 2e4c0a5e2576 ("iio: imu: inv_mpu6050: add fifo temperature data support")
> >
> > Signed-off-by: Tom Rix <trix@redhat.com>  
> 
> There shouldn't be a blank line in between.
> 
> Other than that,
> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> 
> 
> 
> > ---
> >  drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
> > index b533fa2dad0a..5240a400dcb4 100644
> > --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
> > +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
> > @@ -141,6 +141,7 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)
> >
> >         if (!(st->chip_config.accl_fifo_enable |
> >                 st->chip_config.gyro_fifo_enable |
> > +               st->chip_config.temp_fifo_enable |
> >                 st->chip_config.magn_fifo_enable))
> >                 goto end_session;
> >         bytes_per_datum = 0;
> > --
> > 2.18.1
> >  
> 
> 
> --
> With Best Regards,
> Andy Shevchenko

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-09-13 10:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-09 15:59 [PATCH] iio: imu: inv_mpu6050: check for temp_fifo_enable trix
2020-08-10  8:02 ` Andy Shevchenko
2020-08-13  8:04   ` Jean-Baptiste Maneyrol
2020-08-16  8:58     ` Jonathan Cameron

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).