Skip to contentSkip to conversation

media: uvc_video: fix bit overflow in uvc_probe_video

PATCH Superseded Hangyu Hua 2 participants 3 messages Mar 24, 2022 – Mar 25, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Hangyu Hua

author
#0 lore raw

PATCH 1/1 media: uvc_video: fix bit overflow in uvc_probe_video

probe->dwMaxPayloadTransferSize is a 32bit value, but bandwidth is 16bit. This may lead to a bit overflow.

---
 drivers/media/usb/uvc/uvc_video.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/usb/uvc/uvc_video.c +2 -2
index 1b4cc934109e..cc4878373aa7 100644
@@ -383,7 +383,7 @@ int uvc_probe_video(struct uvc_streaming *stream,
 	struct uvc_streaming_control *probe)
 {
 	struct uvc_streaming_control probe_min, probe_max;
-	u16 bandwidth;
+	u32 bandwidth;
 	unsigned int i;
 	int ret;
 
@@ -422,7 +422,7 @@ int uvc_probe_video(struct uvc_streaming *stream,
 			break;
 
 		bandwidth = probe->dwMaxPayloadTransferSize;
-		if (bandwidth <= stream->maxpsize)
+		if (bandwidth <= (u32)stream->maxpsize)
 			break;
 
 		if (stream->dev->quirks & UVC_QUIRK_PROBE_MINMAX) {
Signature · 1 line
2.25.1
maintainer
#1 lore raw

Hi Hangyu,

Thank you for the patch.

Quoted 22 lines · Hangyu Hua

probe->dwMaxPayloadTransferSize is a 32bit value, but bandwidth is 16bit. This may lead to a bit overflow.

---
 drivers/media/usb/uvc/uvc_video.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/usb/uvc/uvc_video.c +1 -1
index 1b4cc934109e..cc4878373aa7 100644
@@ -383,7 +383,7 @@ int uvc_probe_video(struct uvc_streaming *stream,
 	struct uvc_streaming_control *probe)
 {
 	struct uvc_streaming_control probe_min, probe_max;
-	u16 bandwidth;
+	u32 bandwidth;
 	unsigned int i;
 	int ret;
 

drivers/media/usb/uvc/uvc_video.c int uvc_probe_video(struct uvc_streaming *stream, · line 425

Quoted 5 lines
drivers/media/usb/uvc/uvc_video.c +1 -1
@@ -422,7 +422,7 @@ int uvc_probe_video(struct uvc_streaming *stream,
 			break;
 
 		bandwidth = probe->dwMaxPayloadTransferSize;
-		if (bandwidth <= stream->maxpsize)
+		if (bandwidth <= (u32)stream->maxpsize)

The cast to u32 isn't needed, it's implicit.

This could actually be written

	if (probe->dwMaxPayloadTransferSize <= stream->maxpsize)

The bandwidth local variable can be dropped. Could you submit a v2 with this change ?

Quoted 3 lines
drivers/media/usb/uvc/uvc_video.c +0 -0
 			break;
 
 		if (stream->dev->quirks & UVC_QUIRK_PROBE_MINMAX) {
Signature · 3 lines
Regards,

Laurent Pinchart
author
#2 lore raw

Thanks. I will do it.

Quoted 46 lines · Laurent Pinchart

Hi Hangyu,

Thank you for the patch.

Quoted 22 lines · Hangyu Hua

probe->dwMaxPayloadTransferSize is a 32bit value, but bandwidth is 16bit. This may lead to a bit overflow.

---
  drivers/media/usb/uvc/uvc_video.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/usb/uvc/uvc_video.c +1 -1
index 1b4cc934109e..cc4878373aa7 100644
@@ -383,7 +383,7 @@ int uvc_probe_video(struct uvc_streaming *stream,
  	struct uvc_streaming_control *probe)
  {
  	struct uvc_streaming_control probe_min, probe_max;
-	u16 bandwidth;
+	u32 bandwidth;
  	unsigned int i;
  	int ret;
 

drivers/media/usb/uvc/uvc_video.c int uvc_probe_video(struct uvc_streaming *stream, · line 425

Quoted 5 lines
drivers/media/usb/uvc/uvc_video.c +1 -1
@@ -422,7 +422,7 @@ int uvc_probe_video(struct uvc_streaming *stream,
  			break;
 
  		bandwidth = probe->dwMaxPayloadTransferSize;
-		if (bandwidth <= stream->maxpsize)
+		if (bandwidth <= (u32)stream->maxpsize)

The cast to u32 isn't needed, it's implicit.

This could actually be written

	if (probe->dwMaxPayloadTransferSize <= stream->maxpsize)

The bandwidth local variable can be dropped. Could you submit a v2 with this change ?

Quoted 3 lines
drivers/media/usb/uvc/uvc_video.c +0 -0
  			break;
 
  		if (stream->dev->quirks & UVC_QUIRK_PROBE_MINMAX) {