mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] kfifo: do not allocate a fifo smaller than 2 bytes
Date: Fri, 17 Apr 2026 11:36:59 +0200	[thread overview]
Message-ID: <20260417093701.3860735-1-a.fatoum@pengutronix.de> (raw)

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




             reply	other threads:[~2026-04-17  9:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-17  9:36 Ahmad Fatoum [this message]
2026-04-17 10:45 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260417093701.3860735-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox