From e93e7fd9f5a3fffec7792dbcc4c3574653effda7 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Tue, 9 Sep 2014 04:42:43 -0300 Subject: [PATCH] [media] v4l2: uvcvideo: Allow using larger buffers A test in uvc_video_decode_isoc() checks whether an image has been received from the camera completely. For this the data amount is compared to the buffer length, which, however, doesn't have to be equal to the image size. Switch to using formats .sizeimage field for an exact expected image size. [Renamed image_size to frame_size] Signed-off-by: Guennadi Liakhovetski Signed-off-by: Laurent Pinchart Signed-off-by: Mauro Carvalho Chehab --- drivers/media/usb/uvc/uvc_v4l2.c | 1 + drivers/media/usb/uvc/uvc_video.c | 2 +- drivers/media/usb/uvc/uvcvideo.h | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 378ae02e593b..60a8e2c3631e 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -318,6 +318,7 @@ static int uvc_v4l2_set_format(struct uvc_streaming *stream, stream->ctrl = probe; stream->cur_format = format; stream->cur_frame = frame; + stream->frame_size = fmt->fmt.pix.sizeimage; done: mutex_unlock(&stream->mutex); diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index a2bddf48171f..9ace520bb079 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -1143,7 +1143,7 @@ static int uvc_video_encode_data(struct uvc_streaming *stream, static void uvc_video_validate_buffer(const struct uvc_streaming *stream, struct uvc_buffer *buf) { - if (buf->length != buf->bytesused && + if (stream->frame_size != buf->bytesused && !(stream->cur_format->flags & UVC_FMT_FLAG_COMPRESSED)) buf->error = 1; } diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 39c4f941b63d..6f676c29ec09 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -457,6 +457,8 @@ struct uvc_streaming { struct uvc_format *def_format; struct uvc_format *cur_format; struct uvc_frame *cur_frame; + size_t frame_size; + /* Protect access to ctrl, cur_format, cur_frame and hardware video * probe control. */ -- 2.20.1