[PATCH] kfifo: do not allocate a fifo smaller than 2 bytes

Ahmad Fatoum a.fatoum at pengutronix.de
Fri Apr 17 02:36:59 PDT 2026


Linux also refuses allocation of such FIFOs and if such argument indeed
passes, it's most likely a bug, so exit early.

All users of kfifo_init in barebox currently pass a fixed larger
power-of-two argument, except for TFTP, which calculates it dynamically,
but this is fixed separately. This patch is thus just to future proof.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 lib/kfifo.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/kfifo.c b/lib/kfifo.c
index fa22feb7e082..bf1ab138c6e6 100644
--- a/lib/kfifo.c
+++ b/lib/kfifo.c
@@ -50,6 +50,9 @@ struct kfifo *kfifo_alloc(unsigned int size)
 	unsigned char *buffer;
 	struct kfifo *fifo;
 
+	if (size < 2)
+		return NULL;
+
 	/*
 	 * round up to the next power of 2, since our 'let the indices
 	 * wrap' tachnique works only in this case.
-- 
2.47.3




More information about the barebox mailing list