From: Simon Glass <simon.glass@canonical.com>
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 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---
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
@@ -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 <linux/minmax.h>
/* Quota stub */
#define dquot_reclaim_block(i, n) do { } while (0)
new file mode 100644
@@ -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 <linux/types.h>
+
+/**
+ * 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 */