All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: linux-iio@vger.kernel.org
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	kernel test robot <lkp@intel.com>,
	Stefan Windfeldt-Prytz <stefan.windfeldt-prytz@axis.com>
Subject: [PATCH] iio: light: opt4001: Fix a wrong array iteration limit
Date: Mon,  7 Aug 2023 20:50:43 +0100	[thread overview]
Message-ID: <20230807195043.200767-1-jic23@kernel.org> (raw)

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

In practice it's unlikely anyone would try to set the integration time
to 0 which isn't in the available list and if they did then they would
get index 12 which whilst reserved on the device fits in the field.
However a compiler might get half way through this reasoning and that
might be the cause of

> >> drivers/iio/light/opt4001.c:215:9: error: call to '__compiletime_assert_355' declared with 'error' attribute: FIELD_PREP: value too large for the field
>      215 |         reg |= FIELD_PREP(OPT4001_CTRL_CONV_TIME_MASK, chip->int_time);

Even if this isn't the cause, it looks like a bug to me.

Fixes: 9a9608418292 ("iio: light: Add support for TI OPT4001 light sensor")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202308061902.0gVz6bSe-lkp@intel.com/
Cc: Stefan Windfeldt-Prytz <stefan.windfeldt-prytz@axis.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 drivers/iio/light/opt4001.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/light/opt4001.c b/drivers/iio/light/opt4001.c
index 502946bf9f94..83f978706758 100644
--- a/drivers/iio/light/opt4001.c
+++ b/drivers/iio/light/opt4001.c
@@ -137,7 +137,7 @@ static int opt4001_als_time_to_index(const u32 als_integration_time)
 {
 	int i;
 
-	for (i = 0; i < ARRAY_SIZE(opt4001_int_time_available); i++) {
+	for (i = 0; i < ARRAY_SIZE(opt4001_int_time_available) / 2; i++) {
 		if (als_integration_time == opt4001_int_time_available[i][1])
 			return i;
 	}
-- 
2.41.0


             reply	other threads:[~2023-08-07 19:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-07 19:50 Jonathan Cameron [this message]
2023-08-08 15:07 ` [PATCH] iio: light: opt4001: Fix a wrong array iteration limit 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=20230807195043.200767-1-jic23@kernel.org \
    --to=jic23@kernel.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=stefan.windfeldt-prytz@axis.com \
    /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.