[PATCH 0/2] Introduce in_range_incl() inclusive range check macro

Guru Das Srinagesh posted 2 patches 1 month, 1 week ago
There is a newer version of this series
drivers/iio/imu/bmi270/bmi270_core.c |  6 +++---
include/linux/minmax.h               | 21 +++++++++++++++++++++
2 files changed, 24 insertions(+), 3 deletions(-)
[PATCH 0/2] Introduce in_range_incl() inclusive range check macro
Posted by Guru Das Srinagesh 1 month, 1 week ago
Extend the existing in_range() API to provide a user-friendly inclusive
range check and add one illustrative in-tree example of its use.

The in_range() API lends itself easily to callers who care about a
half-open range, but has no straightforward equivalent for callers that
want to check for an inclusive range. Such callers have to resort to
this pattern:

	in_range(val, start, (end - start + 1))

which is quite clunky and easy to mess up. Examples of such callers:

- fs/btrfs/extent-io-tree.c hand-computes the inclusive check by
  passing "state->end - state->start + 1" as in_range()'s len argument.
- drivers/md/dm-raid.c has its own file-local __within_range(v, min, max)
  helper, independently invented, with almost a dozen call sites in
  that one file.
- drivers/iio/imu/bmi270/bmi270_core.c has three "in_range(val, 0,
  MAX + 1)" checks in bmi270_write_event_value(), computing the +1 by
  hand for the same reason.

This series converts only bmi270_core.c as a first step, as an exemplar
for the usage of the new API.

Signed-off-by: Guru Das Srinagesh <linux@gurudas.dev>
---
Guru Das Srinagesh (2):
      minmax: Add in_range_incl() for inclusive range checks
      iio: imu: bmi270: Use in_range_incl() in bmi270_write_event_value()

 drivers/iio/imu/bmi270/bmi270_core.c |  6 +++---
 include/linux/minmax.h               | 21 +++++++++++++++++++++
 2 files changed, 24 insertions(+), 3 deletions(-)
---
base-commit: f5098b6bae761e346ebcd9da7f95622c04733cff
change-id: 20260815-minmax-in-range-incl-a25c242be676

Best regards,
--  
Guru Das Srinagesh <linux@gurudas.dev>