From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Fri, 17 Apr 2026 11:37:34 +0200 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by lore.white.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wDfdm-00D8xe-2S for lore@lore.pengutronix.de; Fri, 17 Apr 2026 11:37:34 +0200 Received: from bombadil.infradead.org ([2607:7c80:54:3::133]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1wDfdm-0003WF-7k for lore@pengutronix.de; Fri, 17 Apr 2026 11:37:34 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=U4sgyap79MCtS13TiKF5TqKKE9pecxiRpOYLRQOXOXw=; b=pGTMLrVV1691Xzqso818w6E+Jw zgv2eQ/lB+vZy841hhu/DljqNCfBimXqNlqyDnRz1n4PDH9g1Qt9qiDBO9bJxkb2KzqV/r29/K18V TWyU6lMOfsK7dbvn0GZbL0Px22Uu/LqjJ5KzC7xhxajtpdYSN1Co92HdxCf/zyCuTBfOQPYuBKLB4 nP/gb0w/99UYkqNFROTQJMX02MifqjkeyoDJ+lfRKhJlC811nwouTCL4ZUMoV1D6R9R3GZeKnoNrs lir6L9wZOrAf7JmuKB0ttKW2tcam5+htn+55DOSU9/UsOLZ9/DomyQAQ3WaXLubPML3zKsx/v81U/ TTLLjTyg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1wDfdQ-00000003qII-3v2v; Fri, 17 Apr 2026 09:37:12 +0000 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1wDfdO-00000003qHq-25Ii for barebox@lists.infradead.org; Fri, 17 Apr 2026 09:37:11 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1wDfdM-0003Ji-PT; Fri, 17 Apr 2026 11:37:08 +0200 Received: from dude05.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::54]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wDfdM-005pIv-1w; Fri, 17 Apr 2026 11:37:08 +0200 Received: from [::1] (helo=dude05.red.stw.pengutronix.de) by dude05.red.stw.pengutronix.de with esmtp (Exim 4.98.2) (envelope-from ) id 1wDfdM-0000000GCM9-27gA; Fri, 17 Apr 2026 11:37:08 +0200 From: Ahmad Fatoum To: barebox@lists.infradead.org Cc: Ahmad Fatoum Date: Fri, 17 Apr 2026 11:36:59 +0200 Message-ID: <20260417093701.3860735-1-a.fatoum@pengutronix.de> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260417_023710_542291_716960ED X-CRM114-Status: UNSURE ( 9.71 ) X-CRM114-Notice: Please train this message. X-BeenThere: barebox@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "barebox" X-SA-Exim-Connect-IP: 2607:7c80:54:3::133 X-SA-Exim-Mail-From: barebox-bounces+lore=pengutronix.de@lists.infradead.org X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on metis.whiteo.stw.pengutronix.de X-Spam-Level: X-Spam-Status: No, score=-5.2 required=4.0 tests=AWL,BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.2 Subject: [PATCH] kfifo: do not allocate a fifo smaller than 2 bytes X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on metis.whiteo.stw.pengutronix.de) 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 --- 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