From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH] usb: gadget: fastboot: correctly cap rx_bytes_expected() result
Date: Sun, 25 Oct 2026 17:01:37 +0100 [thread overview]
Message-ID: <20261025160138.3019136-1-a.fatoum@barebox.org> (raw)
The function only ever returns an unsigned value and
fastboot.download_{size,bytes} are both unsigned values too.
Storing their difference into an int may possibly lead to misbehavior,
so fix the types to ensure no overflow can happen.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
drivers/usb/gadget/function/f_fastboot.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/gadget/function/f_fastboot.c b/drivers/usb/gadget/function/f_fastboot.c
index 85732802ff80..8f7390fd2403 100644
--- a/drivers/usb/gadget/function/f_fastboot.c
+++ b/drivers/usb/gadget/function/f_fastboot.c
@@ -445,10 +445,10 @@ static int fastboot_write_usb(struct fastboot *fb, const char *buffer, unsigned
return 0;
}
-static int rx_bytes_expected(struct f_fastboot *f_fb)
+static unsigned rx_bytes_expected(struct f_fastboot *f_fb)
{
- int remaining = f_fb->fastboot.download_size
- - f_fb->fastboot.download_bytes;
+ size_t remaining = f_fb->fastboot.download_size
+ - f_fb->fastboot.download_bytes;
if (remaining >= EP_BUFFER_SIZE)
return EP_BUFFER_SIZE;
--
2.47.3
next reply other threads:[~2026-10-25 16:03 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-25 16:01 Ahmad Fatoum [this message]
2026-10-26 12:57 ` 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=20261025160138.3019136-1-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--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