From: Eli Billauer <eli.billauer@gmail.com>
To: gregkh@linuxfoundation.org
Cc: arnd@arndb.de, linux-kernel@vger.kernel.org,
Eli Billauer <eli.billauer@gmail.com>
Subject: [PATCH v2 1/8] char: xillybus: Improve sanity check
Date: Tue, 17 Nov 2026 12:58:55 +0100 [thread overview]
Message-ID: <20261117115902.41359-2-eli.billauer@gmail.com> (raw)
In-Reply-To: <20261117115902.41359-1-eli.billauer@gmail.com>
The sanity check in fifo_init() added in commit 1ce74f6f2216 ("char:
xillybus: Add defensive sanity checks") is unnecessarily complicated
and may not work as expected due to the incorrect assumption that
1 << n == 0 when n>31 due to overflow. Replace it with a single
check at the function's invocation. This check also eliminates any
possibility for overflow in this function's left-shift operations.
Fixes: 1ce74f6f2216 ("char: xillybus: Add defensive sanity checks")
Assisted-by: Sashiko-0.2.5:gemini-3.1-pro-preview
Link: https://sashiko.dev/#/patchset/20261109112800.48663-1-eli.billauer@gmail.com
Signed-off-by: Eli Billauer <eli.billauer@gmail.com>
---
Notes:
Changes in v2:
- New patch, replacing v1's "char: xillybus: Use unsigned int
literal". Following Sashiko's review, reject log2_size >
ilog2(SZ_1G) before the left-shift operations, instead of relying
on the overflow check, which a shift by 32 bits or more could
bypass.
drivers/char/xillybus/xillyusb.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/char/xillybus/xillyusb.c b/drivers/char/xillybus/xillyusb.c
index bd3babd39f35..c4ddde221f0b 100644
--- a/drivers/char/xillybus/xillyusb.c
+++ b/drivers/char/xillybus/xillyusb.c
@@ -374,6 +374,9 @@ static int fifo_init(struct xillyfifo *fifo,
unsigned int log2_fifo_buf_size;
+ if (log2_size > ilog2(SZ_1G))
+ return -ENOMEM; /* Reported as greed for memory */
+
mutex_lock(&fifo_buf_order_mutex);
retry:
@@ -390,12 +393,6 @@ static int fifo_init(struct xillyfifo *fifo,
fifo->bufnum = 1 << log2_bufnum;
fifo->size = fifo->bufnum * fifo->bufsize;
- if (!fifo->size || /* Unsigned integer overflow */
- fifo->size > SZ_1G) { /* Avoid signed int issues */
- mutex_unlock(&fifo_buf_order_mutex);
- return -ENOMEM; /* Reported as greed for memory */
- }
-
fifo->mem = kmalloc_array(fifo->bufnum, sizeof(void *), GFP_KERNEL);
if (!fifo->mem) {
--
2.17.1
next prev parent reply other threads:[~2026-11-17 11:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 11:58 [PATCH v2 0/8] char: xillybus: Fix issues reported by Sashiko Eli Billauer
2026-11-17 11:58 ` Eli Billauer [this message]
2026-11-17 11:58 ` [PATCH v2 2/8] char: xillybus: Safer access of unaligned pointers Eli Billauer
2026-11-17 11:58 ` [PATCH v2 3/8] char: xillybus: Return error in fops read method handler Eli Billauer
2026-11-17 11:58 ` [PATCH v2 4/8] char: xillybus: Rely on FMODE flags in poll method Eli Billauer
2026-11-17 11:58 ` [PATCH v2 5/8] char: xillybus: Refactor flush function Eli Billauer
2026-11-17 11:59 ` [PATCH v2 6/8] char: xillybus: Correct handling of wait queue Eli Billauer
2026-11-17 11:59 ` [PATCH v2 7/8] char: xillybus: Avoid indefinite sleep of work item Eli Billauer
2026-11-17 11:59 ` [PATCH v2 8/8] char: xillybus: Cancel delayed work items before teardown Eli Billauer
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=20261117115902.41359-2-eli.billauer@gmail.com \
--to=eli.billauer@gmail.com \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.