diff options
| author | Jean-Sébastien Pédron <dumbbell@FreeBSD.org> | 2026-04-22 14:36:06 +0000 |
|---|---|---|
| committer | Jean-Sébastien Pédron <dumbbell@FreeBSD.org> | 2026-04-22 20:46:57 +0000 |
| commit | 9a2de1d2042d1c2730dd3049c26d481813b5f2bd (patch) | |
| tree | 497b535d6da5af2e9a30b8c88744046cb7d5aaf7 | |
| parent | 5dfbc6593cdacd5b4e4939e09d595b3a9c8e47da (diff) | |
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
Differential Revision: https://reviews.freebsd.org/D56583
| -rw-r--r-- | sys/compat/linuxkpi/common/include/linux/minmax.h | 10 |
1 files changed, 10 insertions, 0 deletions
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_ */ |
