From 796fff59a5d32bc3be14feaeb228fc15ef43eb32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20P=C3=A9dron?= Date: Mon, 13 Apr 2026 23:44:16 +0200 Subject: [PATCH] linuxkpi: Define `DEFINE_XARRAY*()` macros The `DEFINE_XARRAY*()` macros are used to declare a static xarray. As the structure embeds a mutex(9), we also need to declare the static mutex after the `struct xarray`. Thus the slightly awkward definition of `DEFINE_XARRAY_FLAGS()`. The DRM generic code started to use `DEFINE_XARRAY_ALLOC()` in Linux 6.12. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56446 --- sys/compat/linuxkpi/common/include/linux/xarray.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/xarray.h b/sys/compat/linuxkpi/common/include/linux/xarray.h index e6511130d50..b26aa6f0d13 100644 --- a/sys/compat/linuxkpi/common/include/linux/xarray.h +++ b/sys/compat/linuxkpi/common/include/linux/xarray.h @@ -54,6 +54,18 @@ struct xarray { uint32_t xa_flags; /* see XA_FLAGS_XXX */ }; +#define DEFINE_XARRAY_FLAGS(name, flags) \ + struct xarray name = { \ + .xa_head.gfp_mask = GFP_NOWAIT, \ + .xa_flags = flags, \ + }; \ + MTX_SYSINIT(name ## _mtx, &name.xa_lock, \ + "linuxkpi_DEFINE_XARRAY(" #name ")", \ + MTX_DEF | MTX_RECURSE) + +#define DEFINE_XARRAY(name) DEFINE_XARRAY_FLAGS(name, 0) +#define DEFINE_XARRAY_ALLOC(name) DEFINE_XARRAY_FLAGS(name, XA_FLAGS_ALLOC) + struct xa_limit { uint32_t max; uint32_t min;