From: Guru Das Srinagesh <linux@gurudas.dev>
To: "Alex Lanzano" <lanzano.alex@gmail.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Matthew Wilcox" <willy@infradead.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Gustavo Silva" <gustavograzs@gmail.com>
Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org,
Guru Das Srinagesh <linux@gurudas.dev>
Subject: [PATCH v2 2/2] iio: imu: bmi270: Use in_range_inclusive() in bmi270_write_event_value()
Date: Sun, 16 Aug 2026 12:26:21 -0700 [thread overview]
Message-ID: <20260816-minmax-in-range-incl-v2-2-766f737dd6bf@gurudas.dev> (raw)
In-Reply-To: <20260816-minmax-in-range-incl-v2-0-766f737dd6bf@gurudas.dev>
Replace the three "in_range(val, 0, MAX + 1)" checks with the new
in_range_inclusive() helper, expressing each as the inclusive [0, MAX]
range it actually validates.
No functional change.
Assisted-by: Claude-Code:claude-sonnet-5
Signed-off-by: Guru Das Srinagesh <linux@gurudas.dev>
---
drivers/iio/imu/bmi270/bmi270_core.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/imu/bmi270/bmi270_core.c b/drivers/iio/imu/bmi270/bmi270_core.c
index 2ad230788532..7f386a615b39 100644
--- a/drivers/iio/imu/bmi270/bmi270_core.c
+++ b/drivers/iio/imu/bmi270/bmi270_core.c
@@ -1132,7 +1132,7 @@ static int bmi270_write_event_value(struct iio_dev *indio_dev,
guard(mutex)(&data->mutex);
if (type == IIO_EV_TYPE_CHANGE) {
- if (!in_range(val, 0, BMI270_STEP_COUNTER_MAX + 1))
+ if (!in_range_inclusive(val, 0, BMI270_STEP_COUNTER_MAX))
return -EINVAL;
raw = val / BMI270_STEP_COUNTER_FACTOR;
@@ -1152,7 +1152,7 @@ static int bmi270_write_event_value(struct iio_dev *indio_dev,
if (ret)
return ret;
- if (!in_range(val, 0, (BMI270_G_MICRO_M_S_2 / uscale) + 1))
+ if (!in_range_inclusive(val, 0, BMI270_G_MICRO_M_S_2 / uscale))
return -EINVAL;
tmp = (u64)val * BMI270_MOTION_THRES_FULL_SCALE * uscale;
@@ -1161,7 +1161,7 @@ static int bmi270_write_event_value(struct iio_dev *indio_dev,
regval = FIELD_PREP(BMI270_FEAT_MOTION_THRESHOLD_MSK, raw);
return bmi270_update_feature_reg(data, reg, mask, regval);
case IIO_EV_INFO_PERIOD:
- if (!in_range(val, 0, BMI270_MOTION_DURAT_MAX + 1))
+ if (!in_range_inclusive(val, 0, BMI270_MOTION_DURAT_MAX))
return -EINVAL;
raw = BMI270_INT_MICRO_TO_RAW(val, val2,
--
2.55.0
next prev parent reply other threads:[~2026-08-16 19:31 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-16 19:26 [PATCH v2 0/2] Introduce in_range_incl() inclusive range check macro Guru Das Srinagesh
2026-08-16 19:26 ` [PATCH v2 1/2] minmax: Add in_range_inclusive() for inclusive range checks Guru Das Srinagesh
2026-08-16 21:34 ` Matthew Wilcox
2026-08-31 16:29 ` Guru Das Srinagesh
2026-08-17 8:06 ` Andy Shevchenko
2026-08-31 16:33 ` Guru Das Srinagesh
2026-08-16 19:26 ` Guru Das Srinagesh [this message]
2026-08-17 3:00 ` [PATCH v2 2/2] iio: imu: bmi270: Use in_range_inclusive() in bmi270_write_event_value() 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=20260816-minmax-in-range-incl-v2-2-766f737dd6bf@gurudas.dev \
--to=linux@gurudas.dev \
--cc=akpm@linux-foundation.org \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=gustavograzs@gmail.com \
--cc=jic23@kernel.org \
--cc=lanzano.alex@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=willy@infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®