From nobody Mon Sep 28 22:31:39 2026 Received: from out-2z4y-a134.jellyfish.systems (out-2z4y-a134.jellyfish.systems [198.54.127.134]) (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 B0DD73168EE for ; Sun, 16 Aug 2026 03:17:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.54.127.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786850244; cv=none; b=OW6dbTA0nrbLuJYeUpjw90tHKEKEsHMvDcu00Zu1a7o+LNyfL7AJ0xMvXPNUJwDqRHOAl+YsMoVS0dp9z1hcm0tZs+KYA7o3iZBOrrueOLWDlANpcM5XrKnnOM6ZHHZS03Tjvn6Lu6HYQtAQBRB0u4OWOOlKJAsXbONfqEXBobE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786850244; c=relaxed/simple; bh=NHh28Z/L+K1RIQLgI/89sIMruMYooHxghvdx04Ga85E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lzo6NI9JOuK9JV/0xk08uNblwnQwwpEuxCrWwALtSIiDbZdEFddiDd9gzfL6zJizgRNUQNj6SAwKNyWvQvDJ/jP/r8YlwZdP3gTUl39L76fTsRus/jIM8YebcQErexuiDhGlf9lBnxpQqkQj5qwmtKunx3eDbkJFFkUXgZGudkc= 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=WtxMlwor; arc=none smtp.client-ip=198.54.127.134 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="WtxMlwor" Received: from [192.168.1.103] (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 4hN1NT4p99z8sWl; Sun, 16 Aug 2026 03:17:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gurudas.dev; s=spacemail; t=1786850235; bh=CnYGatwbfHvnqD597S0FvDh1toctwxoutBgYI1Nc/2A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=WtxMlworaUQ4BbJQcNBQkTMxr0HSvh0SUJNSu7hvk2jj99qOG7Mure2KkBv3y8pBH hIXQxMYa/DyaN1hLRDLadL8oXAufET0zcN64AAGWMob8M8JJKf1Of58YVrQEF8k1ZG kwSBcdt1hQTHhOWKus3DIj/fqHeWC4zyq1vdUlvJGjcwIo8ER8oeRakfi8569k58zF w3fGo3T3U/RTvaZYaEQlPI66A0AK2GGRqOalMEFjcpcGiRSnbzCNazbVqJAEuBoeRu aFq1eTvePxZ/22tMFWyT940vCUGxpKsoVjGWUD4MxPlcVbzEjCkqtWwKKCBN2sFS7T E701/UVC1pehw== From: Guru Das Srinagesh Date: Sat, 15 Aug 2026 20:17:09 -0700 Subject: [PATCH 1/2] minmax: Add in_range_incl() 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: <20260815-minmax-in-range-incl-v1-1-a75f7d9ae92e@gurudas.dev> References: <20260815-minmax-in-range-incl-v1-0-a75f7d9ae92e@gurudas.dev> In-Reply-To: <20260815-minmax-in-range-incl-v1-0-a75f7d9ae92e@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 function/macro to reach for and either hand-roll the comparison or convert it to in_range()'s (start, len) form themselves. Add in_range_incl(val, start, end), computing len as end - start + 1 and forwarding to in_range() so it inherits the existing 32-bit/64-bit type dispatch rather than risking silent truncation from a fresh hand-rolled comparison. val, start and end are each assigned to a temporary variable before use, so each is evaluated exactly once regardless of how many times it appears in the expansion (matching swap()'s __tmp below). Assisted-by: Claude-Code:claude-sonnet-5 Signed-off-by: Guru Das Srinagesh --- include/linux/minmax.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index a0158db54a04..71900d688a06 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -299,6 +299,27 @@ 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 +/** + * in_range_incl - Determine if a value lies within an inclusive range. + * @val: Value to test. + * @start: First value in range. + * @end: Last value in range. + * + * @val, @start and @end are each evaluated exactly once. + * + * Same caveats as in_range() apply. In particular, if @end sits at the + * maximum value representable by the common type of @start and @end, + * "@end - @start + 1" wraps to 0, silently rejecting every @val instead + * of accepting all of them. Callers must ensure @end - @start + 1 does + * not overflow, and that @end >=3D @start. + */ +#define in_range_incl(val, start, end) ({ \ + typeof(val) __val =3D (val); \ + typeof(start) __start =3D (start); \ + typeof(end) __end =3D (end); \ + in_range(__val, __start, __end - __start + 1); \ +}) + /** * swap - swap values of @a and @b * @a: first value --=20 2.55.0 From nobody Mon Sep 28 22:31:39 2026 Received: from out-2z4y-a134.jellyfish.systems (out-2z4y-a134.jellyfish.systems [198.54.127.134]) (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 7286933FE0A for ; Sun, 16 Aug 2026 03:17:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.54.127.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786850244; cv=none; b=BkYeCwj47LWNFLPaqm2EQonQE2qUUQhIO7MkcNDLeHKZqbwVjiu/flcAMQEq/doa1RVTLwsX1wMZPnvGnYF00vYU/jEg+MMVU9hJnwKkPwOMDxD0yFGVvk/9iuRQ7ULCmutx2JOMieRTSdKqSvMCyLyNEYde52cN1P0qOJDE10Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786850244; c=relaxed/simple; bh=aGFFZJFnbM7GtrtzCiVUEL6l7w2mFZNKgMqdn4tOqps=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RX/CFVGKByfedm9+CDNOC6PWvISwPMWs87CVjpxLCc7S8hyowLIj+UQHI6FJ8VpX+A9Gx7TiVQgd8zDqb1oOlLgEWLjotyIvLkJStRrS/Wsj6QP9miTHCw4yrABKR7Ux0f7M9bxSTmcSJP3QtiVAZ3k7cGC0EkOa6lt6VFJFZPQ= 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=ECV9L4+g; arc=none smtp.client-ip=198.54.127.134 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="ECV9L4+g" Received: from [192.168.1.103] (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 4hN1NW16Xxz8sWk; Sun, 16 Aug 2026 03:17:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gurudas.dev; s=spacemail; t=1786850236; bh=pEFMuCMGyKSxBMm1KRuM6omra4CvFV8CDADWc2gDg4s=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ECV9L4+grOlZ94iv8aOt4yuYJtkJsief3yW5tMccPPvPQ4LiZFvUS+/bs7WpuNzFy vE7aGW2W63PjyUZq32PoMtPjrOB2SGHkH8JobCE1HHznl2NPRjjEyn9NMupCUkrkV8 E4GUP8ioZO0p0BAVJK6tFrwrZkWIUPLzTZhnGJCAnh0WI48oLzpZFsUPHzzwEqlsNl 30Mudf3SjrM8t13t3T4qExHifE9T4rQuElwj8Vyn8aFC+1e+6naAwphsAzBe0nta1x D79kPVYqj94oJ0PUNB/en9bECf/x7yEUeWnSpsydEO321WTwk2eroIsP6Nkz8DfczZ C1L7zR4fxNdLw== From: Guru Das Srinagesh Date: Sat, 15 Aug 2026 20:17:10 -0700 Subject: [PATCH 2/2] iio: imu: bmi270: Use in_range_incl() 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: <20260815-minmax-in-range-incl-v1-2-a75f7d9ae92e@gurudas.dev> References: <20260815-minmax-in-range-incl-v1-0-a75f7d9ae92e@gurudas.dev> In-Reply-To: <20260815-minmax-in-range-incl-v1-0-a75f7d9ae92e@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_incl() helper function, expressing each as the inclusive [0, MAX] range it actually validates. 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..fdf7f062e234 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_incl(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_incl(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_incl(val, 0, BMI270_MOTION_DURAT_MAX)) return -EINVAL; =20 raw =3D BMI270_INT_MICRO_TO_RAW(val, val2, --=20 2.55.0