From patchwork Mon Jan 19 06:15:01 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1610 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768803361; bh=tRRVg+wxh/WA4BkIJUy2krcGfhIKmPMyjWtvxBiARhg=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=kmzJ5IYzRpkizflI1dkTppzJya87Ra1IAT62Vf/Drpy0kUi5KZE4BKHSgHiG5uFPt frlo779zowT9D5lI0Rom0FeoBLHmpev6YTkPLb10FUStN5EZW7jP5L04qE5pTTeWv4 t37RmhVsDRcZnCJMosHiYUuIn8Pbg8/5LO0sPsy0Hrk5ydiW54B2AJWbdkXXZsLAeQ TJP+L/LcWoyTUb/hbEi6o/aZKek4Nn41Gg2yBtkISgz0l5dN2XhT6gAthz8AnHgNnM uIrUiqm/CsHcVl9YwBAX1wQ5V9nJCXW2DaYahTCS0QaKHDXFJ5541pxUT2I59BS0H5 TXqgWP+0tDfeQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DFC116913F for ; Sun, 18 Jan 2026 23:16:01 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id CgVUa9s1A36C for ; Sun, 18 Jan 2026 23:16:01 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768803361; bh=tRRVg+wxh/WA4BkIJUy2krcGfhIKmPMyjWtvxBiARhg=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=kmzJ5IYzRpkizflI1dkTppzJya87Ra1IAT62Vf/Drpy0kUi5KZE4BKHSgHiG5uFPt frlo779zowT9D5lI0Rom0FeoBLHmpev6YTkPLb10FUStN5EZW7jP5L04qE5pTTeWv4 t37RmhVsDRcZnCJMosHiYUuIn8Pbg8/5LO0sPsy0Hrk5ydiW54B2AJWbdkXXZsLAeQ TJP+L/LcWoyTUb/hbEi6o/aZKek4Nn41Gg2yBtkISgz0l5dN2XhT6gAthz8AnHgNnM uIrUiqm/CsHcVl9YwBAX1wQ5V9nJCXW2DaYahTCS0QaKHDXFJ5541pxUT2I59BS0H5 TXqgWP+0tDfeQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C9877694C7 for ; Sun, 18 Jan 2026 23:16:01 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768803359; bh=9lZrqEb1obkaQjYATfVaUNjzVJM3iI63Z0VluhNMrHo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=llSozA2rNiQEwaAe2cJwMY5WtHxGGO0J9dNtM4td1XN5hsboWHbrLC5klT6gmhfDR yoL1EC/x07qPImvj6/yiAF27DVgeNJ11DVpcaUnhTQ/GrkeGTnPfJf7dlNeDBIzf6B P/z3nwFpK7eq0aba8wMo++LjjXVSrACKSUJgLs0PwWiD0tkPgODCqvdfxuD3IGH66d v/3s2ySI48sz8QWC76W0JimFuy6aB/a7562UEAXNa/nq91JgCJE5IqOrmZ+MI8VqbD P7/umMag9Ii9WvNhiH5m6JG9q3v86pf5j3OD6wolgXcqEq6+hf9vhXQttywjrfgZEi zN5bWRpTgaOow== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AFCF86913F; Sun, 18 Jan 2026 23:15:59 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id SBtDlytS901g; Sun, 18 Jan 2026 23:15:59 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768803355; bh=MsKuaXJn+tgeicpafcy/KK3PVN6dKFZrHEhk5gLqO3w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=elj1w1VTetr85qrrxJO9BPIi2YB7ZplNznh6hFfCp4Q/bKlfW6wvUtZSnvYbBGf7Y rSiB14kuKNyJEESzHyMKf5N1QHPD+ybtM9R8LoNBHV3PObHgeHP/pHfA14gpV5GfL+ bg/5R6Bwm5KknobmajSAQ7NFHylOBHw23L5YNqFMgI2Dw0hZWoxUtMm73mYfMWQg3A NfS4dniaRcJaKyyV0TTVgWhpfqPiPNdxe0pV3o6qQInnjDBbAUfcWuYYkd5o822/Pn Ihd9CQiKQBTQgLphVCRYj4gFnobLPMlHCJ44Zx6goOqg+ffoeA7O9nEN8oPbx7B62p inTKwZP44f40Q== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 5FF8E694C7; Sun, 18 Jan 2026 23:15:55 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sun, 18 Jan 2026 23:15:01 -0700 Message-ID: <20260119061529.3383191-4-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260119061529.3383191-1-sjg@u-boot.org> References: <20260119061529.3383191-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: W2R7XEQOTBG26RUXWGAMKU342Z4QPIPW X-Message-ID-Hash: W2R7XEQOTBG26RUXWGAMKU342Z4QPIPW X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 03/23] linux: Add minmax.h with in_range helper List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Create linux/minmax.h with in_range(), in_range64(), and in_range32() helper functions for range checking operations. Update ext4_uboot.h to use linux/minmax.h instead of duplicating the in_range definition. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 8 ++----- include/linux/minmax.h | 52 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 include/linux/minmax.h diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 7ad24732cf4..bfeb31f465c 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -815,12 +815,8 @@ static inline unsigned long memweight(const void *ptr, size_t bytes) #define sb_no_casefold_compat_fallback(sb) ({ (void)(sb); 1; }) #define generic_ci_validate_strict_name(d, n) ({ (void)(d); (void)(n); 1; }) -/* in_range helper - check if value is in range [start, start+len) */ -static inline int in_range(unsigned long val, unsigned long start, - unsigned long len) -{ - return val >= start && val < start + len; -} +/* in_range - use linux/minmax.h */ +#include /* Quota stub */ #define dquot_reclaim_block(i, n) do { } while (0) diff --git a/include/linux/minmax.h b/include/linux/minmax.h new file mode 100644 index 00000000000..52ce477459d --- /dev/null +++ b/include/linux/minmax.h @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Min/max and related utilities for U-Boot + * + * Based on Linux minmax.h - min, max, clamp, and range helpers. + */ +#ifndef _LINUX_MINMAX_H +#define _LINUX_MINMAX_H + +#include + +/** + * in_range - check if value is within a range + * @val: value to test + * @start: start of range (inclusive) + * @len: length of range + * + * Return: true if @val is in [@start, @start + @len), false otherwise + */ +static inline bool in_range(unsigned long val, unsigned long start, + unsigned long len) +{ + return val >= start && val < start + len; +} + +/** + * in_range64 - check if 64-bit value is within a range + * @val: value to test + * @start: start of range (inclusive) + * @len: length of range + * + * Return: true if @val is in [@start, @start + @len), false otherwise + */ +static inline bool in_range64(u64 val, u64 start, u64 len) +{ + return (val - start) < len; +} + +/** + * in_range32 - check if 32-bit value is within a range + * @val: value to test + * @start: start of range (inclusive) + * @len: length of range + * + * Return: true if @val is in [@start, @start + @len), false otherwise + */ +static inline bool in_range32(u32 val, u32 start, u32 len) +{ + return (val - start) < len; +} + +#endif /* _LINUX_MINMAX_H */