git: b510eedf7e51 - stable/15 - linuxkpi: Add support for statically-allocated kfifo
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 22 Apr 2026 21:08:07 UTC
The branch stable/15 has been updated by bz:
URL: https://cgit.FreeBSD.org/src/commit/?id=b510eedf7e512019ccac0f5f79e0cb7738dad40b
commit b510eedf7e512019ccac0f5f79e0cb7738dad40b
Author: Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
AuthorDate: 2025-09-07 08:37:27 +0000
Commit: Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2026-04-22 20:56:54 +0000
linuxkpi: Add support for statically-allocated kfifo
The main difference with the dynamically allocated version is that the
structure is initialized with `DECLARE_KFIFO()` which takes the number
of items as an additional argument compared to `DECLARE_KFIFO_PTR()`.
The declared structure is then initialized with `INIT_KFIFO()` which
sets all fields to 0, except `total` which is computed from the size of
the array passed to `DECLARE_KFIFO()`.
The amdgpu DRM driver started to used this in Linux 6.10.
Reviewed by: bz
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D54497
(cherry picked from commit 55bd09ae0fc437c9eb135952ac278540b7388add)
---
sys/compat/linuxkpi/common/include/linux/kfifo.h | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/sys/compat/linuxkpi/common/include/linux/kfifo.h b/sys/compat/linuxkpi/common/include/linux/kfifo.h
index b9f6ecacd3d1..b0d0c17f07e4 100644
--- a/sys/compat/linuxkpi/common/include/linux/kfifo.h
+++ b/sys/compat/linuxkpi/common/include/linux/kfifo.h
@@ -33,8 +33,26 @@
#include <linux/slab.h>
#include <linux/gfp.h>
-#define INIT_KFIFO(x) 0
-#define DECLARE_KFIFO(x, y, z)
+/*
+ * INIT_KFIFO() is used to initialize the structure declared with
+ * DECLARE_KFIFO(). It doesn't work with DECLARE_KFIFO_PTR().
+ */
+#define INIT_KFIFO(_kf) \
+ ({ \
+ (_kf).total = nitems((_kf).head); \
+ (_kf).count = 0; \
+ (_kf).first = 0; \
+ (_kf).last = 0; \
+ })
+
+#define DECLARE_KFIFO(_name, _type, _size) \
+ struct kfifo_ ## _name { \
+ size_t total; \
+ size_t count; \
+ size_t first; \
+ size_t last; \
+ _type head[_size]; \
+ } _name
#define DECLARE_KFIFO_PTR(_name, _type) \
struct kfifo_ ## _name { \