From nobody Mon Aug 24 04:19:11 2026 Received: from out-2uec-a94.jellyfish.systems (out-2uec-a94.jellyfish.systems [63.250.43.94]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2C403C09EF for ; Sun, 16 Aug 2026 19:26:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=63.250.43.94 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786908408; cv=none; b=fyqmpcgRyXjEDkHbrKbPl0C9yZJGQaNUHs+eQNIYGU1eaxbaKXASSe+7Zb5mRLX3xIfDuE2mT1bN+2sxK7sEFIYmz7XBRiLiqsOz0XGYgKfmyltgrtWnGuotUF0AuwSsdyL72GvkUafCrlGN2pe9wPL7qUB+8f1Y/vsAsRH5Kbc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786908408; c=relaxed/simple; bh=kNJE/p5U/Ut621rcQKUq/XB68draGwrEOaQCAgmxvSI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cAPxsvnZQIG2ITPzP26xUwSCr6dO9mK9/u/BCvOzakDU7x7NJP9TW0W+mO5XFtG4YXMqNjlRtUzXL65yQ2o+XlZQ55cgxv6S8Fb7KOOFKcwnumNDsxuap6xAf+YCEKeLX7PBZEITUlOLlg6QD4o+dg9Pe53bg3VkRgO2q0nTwck= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gurudas.dev; spf=pass smtp.mailfrom=gurudas.dev; dkim=pass (2048-bit key) header.d=gurudas.dev header.i=@gurudas.dev header.b=PiUFTqRK; arc=none smtp.client-ip=63.250.43.94 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gurudas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gurudas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gurudas.dev header.i=@gurudas.dev header.b="PiUFTqRK" Received: from [192.168.1.104] (107-194-158-19.lightspeed.sntcca.sbcglobal.net [107.194.158.19]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.spacemail.com (Postfix) with ESMTPSA id 4hNQtl3sT5z2xBv; Sun, 16 Aug 2026 19:26:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gurudas.dev; s=spacemail; t=1786908384; bh=0O8s60OxVMHSptmXEcJ3WO3W3gjMt4Y0FZu7UvHQCQA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=PiUFTqRKFOlAFdq0lpobv2UHyHSWIrXYIFmuwtzpv2VtQ5c+pK6I5Z05HHafDBw/d PRiqpJKAwRrjjBJrkPMhH3SFcoEw+139NC7oh5J6XCKv6Zyh0WOO48bXj6oV5iFQWe FXpBFY67eH+yV/hSND00klw5Eh9jdOZtzHB4C2XP6JQqUZZif7Vrtg2RRfJGGnXs1z CUyaP8EZjB4Zend7wn52/kpjPlG/eFukJRlmhpY/jYZuoTVe4408neHmYHI5iH/Kmu GvhP6IXXCEIcQgflOF7DlTgxlrWqXAVaNjeYbCcLYFP5ilORBg7pj9jAL6qiWyQT0v 4xjGiYdDXbQHQ== From: Guru Das Srinagesh Date: Sun, 16 Aug 2026 12:26:20 -0700 Subject: [PATCH v2 1/2] minmax: Add in_range_inclusive() for inclusive range checks Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260816-minmax-in-range-incl-v2-1-766f737dd6bf@gurudas.dev> References: <20260816-minmax-in-range-incl-v2-0-766f737dd6bf@gurudas.dev> In-Reply-To: <20260816-minmax-in-range-incl-v2-0-766f737dd6bf@gurudas.dev> To: Alex Lanzano , Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Matthew Wilcox , Andrew Morton , Gustavo Silva Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Guru Das Srinagesh X-Mailer: b4 0.15.2 X-Envelope-From: linux@gurudas.dev in_range(val, start, len) takes a start and a length, i.e. a half-open range. Callers that instead have an inclusive [start, end] bound have no ready helper to reach for and either hand-roll the comparison or convert it to in_range()'s (start, len) form themselves. Add in_range_inclusive(val, start, end) as a direct comparison rather than a wrapper around in_range(): computing len as end - start + 1 and forwarding it to in_range() subverts in_range()'s 32-bit/64-bit dispatch for sub-32-bit types via integer promotion, and overflows to 0 when @end is the type's maximum value, silently rejecting every input instead of accepting all of them. val, start and end are each assigned to a __UNIQUE_ID()-generated temporary before use, matching the __cmp_once()/__cmp_once_unique() pattern: each argument is evaluated exactly once, and the temporary can't be shadowed by a caller's own same-named local variable. Assisted-by: Claude-Code:claude-sonnet-5 Signed-off-by: Guru Das Srinagesh --- include/linux/minmax.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index a0158db54a04..cb042733f253 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -299,6 +299,25 @@ static inline bool in_range32(u32 val, u32 start, u32 = len) ((sizeof(start) | sizeof(len) | sizeof(val)) <=3D sizeof(u32) ? \ in_range32(val, start, len) : in_range64(val, start, len)) =20 +#define __in_range_inclusive(val, start, end, uval, ustart, uend) ({ \ + typeof(val) uval =3D (val); \ + typeof(start) ustart =3D (start); \ + typeof(end) uend =3D (end); \ + uval >=3D ustart && uval <=3D uend; \ +}) + +/** + * in_range_inclusive - Determine if a value lies within an inclusive rang= e. + * @val: Value to test. + * @start: First value in range. + * @end: Last value in range. + * + * @val, @start and @end are each evaluated exactly once. + */ +#define in_range_inclusive(val, start, end) \ + __in_range_inclusive(val, start, end, __UNIQUE_ID(val_), \ + __UNIQUE_ID(start_), __UNIQUE_ID(end_)) + /** * swap - swap values of @a and @b * @a: first value --=20 2.55.0 From nobody Mon Aug 24 04:19:11 2026 Received: from out-2z4y-a135.jellyfish.systems (out-2z4y-a135.jellyfish.systems [198.54.127.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C52453C76BB for ; Sun, 16 Aug 2026 19:31:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.54.127.135 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786908716; cv=none; b=NUMV55Hpz6FKEEA53tl16jKFQuwqKs8ACKv7s8rdBy4uAxB0ZbMVP/7tLeJrqRr/N1FQFX0vXjoLpfu/DnBjU7UjOoCoYTAdER4WmeAbDBGa0i/XlhnbQiDfxYv+1PTXyS01gUZce4sQZm2um6H7HfE0IkDapCMmdivPK9fa1wA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786908716; c=relaxed/simple; bh=cTsNzRTilqXtdq5//WH6j43o0iiaxMk9zMpXRgUbrWo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DyBCoM9T9gv5uHC4Y8ksmnIhrMSVdzfFyLbN+YairdYJkimz7rO8xArLEq2WY676dGewIwG1fMs2azT28nnZ9C+MTnGm8Wv2gz3T+Ufona2KK3lf8p/zwRqzGgJxFa1YgN9z8WHcCQ53hKT1RGSyKTVu2G7qwL2+dLZNdFOQHxU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gurudas.dev; spf=pass smtp.mailfrom=gurudas.dev; dkim=pass (2048-bit key) header.d=gurudas.dev header.i=@gurudas.dev header.b=CjsHwqdF; arc=none smtp.client-ip=198.54.127.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gurudas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gurudas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gurudas.dev header.i=@gurudas.dev header.b="CjsHwqdF" Received: from [192.168.1.104] (107-194-158-19.lightspeed.sntcca.sbcglobal.net [107.194.158.19]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.spacemail.com (Postfix) with ESMTPSA id 4hNQtn06Mlz2xBx; Sun, 16 Aug 2026 19:26:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gurudas.dev; s=spacemail; t=1786908386; bh=kkA3d5yArNZAMgQ+2D+cnIfWefjUctmtxT844zZK9Bo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=CjsHwqdFMTk+o1kZU/XbQNtlALC4r9vYbCWh8zK6dW821Nf8+UUgNf9CTgAKcokLu OJA8STqxHavDGl4a86TQ4i4csBg0RTBDfejuJH01jIINBjbQRXx+mT2sCtLKdarYJC QLqiAwtB9SE8hUrufpccnq5dZluanqdv3Wa9Wa9NgfPd99H9iEGJMYd8xdrSehX3eC Wtte2yAJ3P3n8vlzpAi6p8SxpVhHxIUdPGRKcLvWPA1nySuWwEjl9Wyv19A0sEg4dz HXWOd6qX3zLlYo+kdpwjCTb8w0SJJf0YqKuv21NgVoKfuuIsHsfo9mKwQavsSChPYu yWkZLjvB8kbwQ== From: Guru Das Srinagesh Date: Sun, 16 Aug 2026 12:26:21 -0700 Subject: [PATCH v2 2/2] iio: imu: bmi270: Use in_range_inclusive() in bmi270_write_event_value() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260816-minmax-in-range-incl-v2-2-766f737dd6bf@gurudas.dev> References: <20260816-minmax-in-range-incl-v2-0-766f737dd6bf@gurudas.dev> In-Reply-To: <20260816-minmax-in-range-incl-v2-0-766f737dd6bf@gurudas.dev> To: Alex Lanzano , Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Matthew Wilcox , Andrew Morton , Gustavo Silva Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Guru Das Srinagesh X-Mailer: b4 0.15.2 X-Envelope-From: linux@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 --- 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 *i= ndio_dev, guard(mutex)(&data->mutex); =20 if (type =3D=3D 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; =20 raw =3D val / BMI270_STEP_COUNTER_FACTOR; @@ -1152,7 +1152,7 @@ static int bmi270_write_event_value(struct iio_dev *i= ndio_dev, if (ret) return ret; =20 - 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; =20 tmp =3D (u64)val * BMI270_MOTION_THRES_FULL_SCALE * uscale; @@ -1161,7 +1161,7 @@ static int bmi270_write_event_value(struct iio_dev *i= ndio_dev, regval =3D 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; =20 raw =3D BMI270_INT_MICRO_TO_RAW(val, val2, --=20 2.55.0