Re: [PATCH v2 2/2] iio: imu: bmi270: Use in_range_inclusive() in bmi270_write_event_value()
Jonathan Cameron <[email protected]>
| Newsgroups | org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <20260817040006.1778790e@jic23-huawei> |
On Sun, 16 Aug 2026 12:26:21 -0700 Guru Das Srinagesh <[email protected]> wrote: > 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 <[email protected]> I like the improved readability of this, so if you get the implementation issues resolved, this patch is fine by me. Jonathan > --- > 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, >