Skip to contentSkip to conversation

usb: gadget: fastboot: correctly cap rx_bytes_expected() result

PATCH Applied Ahmad Fatoum 2 participants 2 messages Oct 25 – Oct 26 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadget: fastboot: correctly cap rx_bytes_expected() result

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.

---
 drivers/usb/gadget/function/f_fastboot.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/usb/gadget/function/f_fastboot.c +3 -3
index 85732802ff80..8f7390fd2403 100644
@@ -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;
Signature · 1 line
2.47.3
Applied
#1 lore raw
Quoted 8 lines · 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.

[...]

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,

Signature · 1 line
Sascha Hauer <[email protected]>