All of lore.kernel.org
 help / color / mirror / Atom feed
From: trix@redhat.com
To: jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de,
	pmeerw@pmeerw.net, jmaneyrol@invensense.com,
	mirq-linux@rere.qmqm.pl, lee.jones@linaro.org
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Tom Rix <trix@redhat.com>
Subject: [PATCH] iio: imu: inv_mpu6050: check for temp_fifo_enable
Date: Sun,  9 Aug 2020 08:59:36 -0700	[thread overview]
Message-ID: <20200809155936.16898-1-trix@redhat.com> (raw)

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


             reply	other threads:[~2020-08-09 16:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-09 15:59 trix [this message]
2020-08-10  8:02 ` [PATCH] iio: imu: inv_mpu6050: check for temp_fifo_enable Andy Shevchenko
2020-08-13  8:04   ` Jean-Baptiste Maneyrol
2020-08-16  8:58     ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200809155936.16898-1-trix@redhat.com \
    --to=trix@redhat.com \
    --cc=jic23@kernel.org \
    --cc=jmaneyrol@invensense.com \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=lee.jones@linaro.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mirq-linux@rere.qmqm.pl \
    --cc=pmeerw@pmeerw.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.