linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: uvc_video: fix bit overflow in uvc_probe_video
@ 2022-03-24  9:13 Hangyu Hua
  2022-03-24 13:52 ` Laurent Pinchart
  0 siblings, 1 reply; 3+ messages in thread
From: Hangyu Hua @ 2022-03-24  9:13 UTC (permalink / raw)
  To: laurent.pinchart, mchehab; +Cc: linux-media, linux-kernel, Hangyu Hua

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

Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
---
 drivers/media/usb/uvc/uvc_video.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index 1b4cc934109e..cc4878373aa7 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -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) {
-- 
2.25.1


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

* Re: [PATCH] media: uvc_video: fix bit overflow in uvc_probe_video
  2022-03-24  9:13 [PATCH] media: uvc_video: fix bit overflow in uvc_probe_video Hangyu Hua
@ 2022-03-24 13:52 ` Laurent Pinchart
  2022-03-25  1:35   ` Hangyu Hua
  0 siblings, 1 reply; 3+ messages in thread
From: Laurent Pinchart @ 2022-03-24 13:52 UTC (permalink / raw)
  To: Hangyu Hua; +Cc: mchehab, linux-media, linux-kernel

Hi Hangyu,

Thank you for the patch.

On Thu, Mar 24, 2022 at 05:13:08PM +0800, Hangyu Hua wrote:
> probe->dwMaxPayloadTransferSize is a 32bit value, but bandwidth is 16bit. This
> may lead to a bit overflow.
> 
> Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
> ---
>  drivers/media/usb/uvc/uvc_video.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> index 1b4cc934109e..cc4878373aa7 100644
> --- a/drivers/media/usb/uvc/uvc_video.c
> +++ b/drivers/media/usb/uvc/uvc_video.c
> @@ -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)

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 ?

>  			break;
>  
>  		if (stream->dev->quirks & UVC_QUIRK_PROBE_MINMAX) {

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH] media: uvc_video: fix bit overflow in uvc_probe_video
  2022-03-24 13:52 ` Laurent Pinchart
@ 2022-03-25  1:35   ` Hangyu Hua
  0 siblings, 0 replies; 3+ messages in thread
From: Hangyu Hua @ 2022-03-25  1:35 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: mchehab, linux-media, linux-kernel

Thanks. I will do it.

On 2022/3/24 21:52, Laurent Pinchart wrote:
> Hi Hangyu,
> 
> Thank you for the patch.
> 
> On Thu, Mar 24, 2022 at 05:13:08PM +0800, Hangyu Hua wrote:
>> probe->dwMaxPayloadTransferSize is a 32bit value, but bandwidth is 16bit. This
>> may lead to a bit overflow.
>>
>> Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
>> ---
>>   drivers/media/usb/uvc/uvc_video.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
>> index 1b4cc934109e..cc4878373aa7 100644
>> --- a/drivers/media/usb/uvc/uvc_video.c
>> +++ b/drivers/media/usb/uvc/uvc_video.c
>> @@ -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)
> 
> 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 ?
> 
>>   			break;
>>   
>>   		if (stream->dev->quirks & UVC_QUIRK_PROBE_MINMAX) {
> 

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

end of thread, other threads:[~2022-03-25  1:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24  9:13 [PATCH] media: uvc_video: fix bit overflow in uvc_probe_video Hangyu Hua
2022-03-24 13:52 ` Laurent Pinchart
2022-03-25  1:35   ` Hangyu Hua

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).