Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Guru Das Srinagesh <linux@gurudas.dev>
Cc: "Alex Lanzano" <lanzano.alex@gmail.com>,
	"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>,
	linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org
Subject: Re: [PATCH v2 2/2] iio: imu: bmi270: Use in_range_inclusive() in bmi270_write_event_value()
Date: Mon, 17 Aug 2026 04:00:06 +0100	[thread overview]
Message-ID: <20260817040006.1778790e@jic23-huawei> (raw)
In-Reply-To: <20260816-minmax-in-range-incl-v2-2-766f737dd6bf@gurudas.dev>

On Sun, 16 Aug 2026 12:26:21 -0700
Guru Das Srinagesh <linux@gurudas.dev> 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 <linux@gurudas.dev>

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,
> 


      reply	other threads:[~2026-08-17  3:00 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 ` [PATCH v2 2/2] iio: imu: bmi270: Use in_range_inclusive() in bmi270_write_event_value() Guru Das Srinagesh
2026-08-17  3:00   ` Jonathan Cameron [this message]

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=20260817040006.1778790e@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=gustavograzs@gmail.com \
    --cc=lanzano.alex@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@gurudas.dev \
    --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