mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: fastboot: correctly cap rx_bytes_expected() result
@ 2026-10-25 16:01 Ahmad Fatoum
  2026-10-26 12:57 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2026-10-25 16:01 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] usb: gadget: fastboot: correctly cap rx_bytes_expected() result
  2026-10-25 16:01 [PATCH] usb: gadget: fastboot: correctly cap rx_bytes_expected() result Ahmad Fatoum
@ 2026-10-26 12:57 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2026-10-26 12:57 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Sun, 25 Oct 2026 17:01:37 +0100, Ahmad Fatoum wrote:
> 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.
> 
> 
> [...]

Applied, thanks!

[1/1] usb: gadget: fastboot: correctly cap rx_bytes_expected() result
      https://git.pengutronix.de/cgit/barebox/commit/?id=0d9d229fd497 (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-10-26 12:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-25 16:01 [PATCH] usb: gadget: fastboot: correctly cap rx_bytes_expected() result Ahmad Fatoum
2026-10-26 12:57 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox