* [PATCH] kfifo: do not allocate a fifo smaller than 2 bytes
@ 2026-04-17 9:36 Ahmad Fatoum
2026-04-17 10:45 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2026-04-17 9:36 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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@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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] kfifo: do not allocate a fifo smaller than 2 bytes
2026-04-17 9:36 [PATCH] kfifo: do not allocate a fifo smaller than 2 bytes Ahmad Fatoum
@ 2026-04-17 10:45 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2026-04-17 10:45 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Fri, 17 Apr 2026 11:36:59 +0200, Ahmad Fatoum wrote:
> 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.
>
> [...]
Applied, thanks!
[1/1] kfifo: do not allocate a fifo smaller than 2 bytes
https://git.pengutronix.de/cgit/barebox/commit/?id=ae4696c16996 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-17 10:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-17 9:36 [PATCH] kfifo: do not allocate a fifo smaller than 2 bytes Ahmad Fatoum
2026-04-17 10:45 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox