iio: imu: inv_mpu6050: check for temp_fifo_enable
Subsystems (2)
PATCH 1/1 iio: imu: inv_mpu6050: check for temp_fifo_enable
From: Tom Rix <[email protected]>
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.
--- drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 1 + 1 file changed, 1 insertion(+)
drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c +1 -0
@@ -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 ;
Signature · 1 line
2.18.1
Quoted 23 lines · On Sun, Aug 9, 2020 at 7:00 PM <[email protected]> wrote:
From: Tom Rix <[email protected]>
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 checkif (!(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_fifoif (st->chip_config.temp_fifo_enable) bytes_per_datum += INV_MPU6050_BYTES_PER_TEMP_SENSOR;
Quoted 7 lines
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 <[email protected]>
There shouldn't be a blank line in between.
Other than that,
Quoted 17 lines
--- drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c | 1 + 1 file changed, 1 insertion(+)drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c +1
-1@@ -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 ; --
Quoted 2 lines
2.18.1
--
With Best Regards,
Andy Shevchenko
Jean-Baptiste Maneyrol
Reviewed-by Andy ShevchenkoHello,
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 <[email protected]>
Sent: Monday, August 10, 2020 10:02
To: [email protected] <[email protected]>
Cc: Jonathan Cameron <[email protected]>; Hartmut Knaack <[email protected]>; Lars-Peter Clausen <[email protected]>; Peter Meerwald <[email protected]>; Jean-Baptiste Maneyrol <[email protected]>; Michał Mirosław <[email protected]>; Lee Jones <[email protected]>; linux-iio <[email protected]>; Linux Kernel Mailing List <[email protected]>
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.
Quoted 23 lines · On Sun, Aug 9, 2020 at 7:00 PM <[email protected]> wrote:
From: Tom Rix <[email protected]>
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 checkif (!(st->chip_config.accl_fifo_enable |
st->chip_config.gyro_fifo_enable|st->chip_config.magn_fifo_enable)) gotoend_session;bytes_per_datum= 0;But there is another fifo,
temp_fifoif (
st->chip_config.temp_fifo_enable)bytes_per_datum+=INV_MPU6050_BYTES_PER_TEMP_SENSOR;
Quoted 7 lines
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 <[email protected]>
There shouldn't be a blank line in between.
Other than that,
Quoted 10 lines
---
drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c| 1 +1 file changed, 1 insertion(+)drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c +0
-0@@ -141,6 +141,7 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)
Quoted 9 lines
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)) gotoend_session;bytes_per_datum= 0;
--
2.18.1
--
With Best Regards,
Andy Shevchenko
Jonathan Cameron
maintainerQuoted 7 lines · On Thu, 13 Aug 2020 08:04:06 +0000 Jean-Baptiste Maneyrol…
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
Quoted 75 lines
Best regards,
JBFrom: Andy Shevchenko <[email protected]>
Sent: Monday, August 10, 2020 10:02
To: [email protected] <[email protected]>
Cc: Jonathan Cameron <[email protected]>; Hartmut Knaack <[email protected]>; Lars-Peter Clausen <[email protected]>; Peter Meerwald <[email protected]>; Jean-Baptiste Maneyrol <[email protected]>; Michał Mirosław <[email protected]>; Lee Jones <[email protected]>; linux-iio <[email protected]>; Linux Kernel Mailing List <[email protected]>
Subject: Re: [PATCH] iio: imu:inv_mpu6050: check fortemp_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.Quoted 23 lines · On Sun, Aug 9, 2020 at 7:00 PM <[email protected]> wrote:
From: Tom Rix <[email protected]>
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 checkif (!(st->chip_config.accl_fifo_enable |
st->chip_config.gyro_fifo_enable|st->chip_config.magn_fifo_enable)) gotoend_session;bytes_per_datum= 0;But there is another fifo,
temp_fifoif (
st->chip_config.temp_fifo_enable)bytes_per_datum+=INV_MPU6050_BYTES_PER_TEMP_SENSOR;Quoted 7 lines
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 <[email protected]>There shouldn't be a blank line in between.
Other than that,
Reviewed-by Andy Shevchenko <[email protected]>Quoted 10 lines
---
drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c| 1 +1 file changed, 1 insertion(+)drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c +0
-0@@ -141,6 +141,7 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)Quoted 9 lines
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)) gotoend_session;bytes_per_datum= 0;
--
2.18.1--
With Best Regards,
Andy Shevchenko