git: 8f8af3357434 - stable/15 - linuxkpi: Define `min_array()` and `max_array()`
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 29 Apr 2026 21:43:12 UTC
The branch stable/15 has been updated by dumbbell:
URL: https://cgit.FreeBSD.org/src/commit/?id=8f8af3357434b39c4cacbc43c30e9dbfb23df35b
commit 8f8af3357434b39c4cacbc43c30e9dbfb23df35b
Author: Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
AuthorDate: 2026-04-22 14:36:06 +0000
Commit: Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
CommitDate: 2026-04-29 21:04:21 +0000
linuxkpi: Define `min_array()` and `max_array()`
They are macros that return the minimum or maximum values of an array of
integers. They assume that the array contains elements.
The i915 DRM driver started to use `min_array()` in Linux 6.12.x.
Reviewed by: bz
Sponsored by: The FreeBSD Foundation
(cherry picked from commit 9a2de1d2042d1c2730dd3049c26d481813b5f2bd)
---
sys/compat/linuxkpi/common/include/linux/minmax.h | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/sys/compat/linuxkpi/common/include/linux/minmax.h b/sys/compat/linuxkpi/common/include/linux/minmax.h
index 5040d7f9141e..161d0174554a 100644
--- a/sys/compat/linuxkpi/common/include/linux/minmax.h
+++ b/sys/compat/linuxkpi/common/include/linux/minmax.h
@@ -77,4 +77,14 @@
/* XXX would have to make sure both are unsigned. */
#define umin(x, y) MIN(x, y)
+/* This macro assumes that the array has elements inside. */
+#define __minmax_array(op, array, len) ({ \
+ typeof(array[0]) __val = array[0]; \
+ for (typeof(len) __i = 1; __i < len; __i++) \
+ __val = op(__val, array[__i]); \
+ __val; })
+
+#define min_array(array, len) __minmax_array(min, array, len)
+#define max_array(array, len) __minmax_array(max, array, len)
+
#endif /* _LINUXKPI_LINUX_MINMAX_H_ */