2aaba31
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2aaba31
Date: Mon, 18 May 2015 10:53:48 +0300
2aaba31
Subject: [PATCH] v4l: uvcvideo: Fix incorrect bandwidth with Chicony device
2aaba31
 04f2:b50b
2aaba31
2aaba31
The "TOSHIBA Web Camera - 5M" Chicony device (04f2:b50b) seems to
2aaba31
compute the bandwidth on 16 bits and erroneously sign-extend it to
2aaba31
32 bits, resulting in a huge bandwidth value. Detect and fix that
2aaba31
condition by setting the 16 MSBs to 0 when they're all equal to 1.
2aaba31
2aaba31
Reported-by: Hans de Goede <hdegoede@redhat.com>
2aaba31
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2aaba31
---
2aaba31
 drivers/media/usb/uvc/uvc_video.c | 8 ++++++++
2aaba31
 1 file changed, 8 insertions(+)
2aaba31
2aaba31
diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
2aaba31
index 20ccc9d315dc..f839654ea436 100644
2aaba31
--- a/drivers/media/usb/uvc/uvc_video.c
2aaba31
+++ b/drivers/media/usb/uvc/uvc_video.c
2aaba31
@@ -119,6 +119,14 @@ static void uvc_fixup_video_ctrl(struct uvc_streaming *stream,
2aaba31
 		ctrl->dwMaxVideoFrameSize =
2aaba31
 			frame->dwMaxVideoFrameBufferSize;
2aaba31
 
2aaba31
+	/* The "TOSHIBA Web Camera - 5M" Chicony device (04f2:b50b) seems to
2aaba31
+	 * compute the bandwidth on 16 bits and erroneously sign-extend it to
2aaba31
+	 * 32 bits, resulting in a huge bandwidth value. Detect and fix that
2aaba31
+	 * condition by setting the 16 MSBs to 0 when they're all equal to 1.
2aaba31
+	 */
2aaba31
+	if ((ctrl->dwMaxPayloadTransferSize & 0xffff0000) == 0xffff0000)
2aaba31
+		ctrl->dwMaxPayloadTransferSize &= ~0xffff0000;
2aaba31
+
2aaba31
 	if (!(format->flags & UVC_FMT_FLAG_COMPRESSED) &&
2aaba31
 	    stream->dev->quirks & UVC_QUIRK_FIX_BANDWIDTH &&
2aaba31
 	    stream->intf->num_altsetting > 1) {