Commit 23ff6043 authored by Laurent Pinchart's avatar Laurent Pinchart Committed by Mauro Carvalho Chehab

V4L/DVB (11945): uvcvideo: Don't accept to change the format when buffers are allocated.

Setting a new frame format or size will likely change the buffer size required
to store a complete video frame. To avoid a buffer overflow, don't allow
VIDIOC_S_FMT calls when video buffers are already allocated.
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@skynet.be>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent d732c44c
...@@ -172,6 +172,20 @@ int uvc_free_buffers(struct uvc_video_queue *queue) ...@@ -172,6 +172,20 @@ int uvc_free_buffers(struct uvc_video_queue *queue)
return 0; return 0;
} }
/*
* Check if buffers have been allocated.
*/
int uvc_queue_allocated(struct uvc_video_queue *queue)
{
int allocated;
mutex_lock(&queue->mutex);
allocated = queue->count != 0;
mutex_unlock(&queue->mutex);
return allocated;
}
static void __uvc_query_buffer(struct uvc_buffer *buf, static void __uvc_query_buffer(struct uvc_buffer *buf,
struct v4l2_buffer *v4l2_buf) struct v4l2_buffer *v4l2_buf)
{ {
......
...@@ -251,7 +251,7 @@ static int uvc_v4l2_set_format(struct uvc_video_device *video, ...@@ -251,7 +251,7 @@ static int uvc_v4l2_set_format(struct uvc_video_device *video,
if (fmt->type != video->streaming->type) if (fmt->type != video->streaming->type)
return -EINVAL; return -EINVAL;
if (uvc_queue_streaming(&video->queue)) if (uvc_queue_allocated(&video->queue))
return -EBUSY; return -EBUSY;
ret = uvc_v4l2_try_format(video, fmt, &probe, &format, &frame); ret = uvc_v4l2_try_format(video, fmt, &probe, &format, &frame);
......
...@@ -747,6 +747,7 @@ extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, ...@@ -747,6 +747,7 @@ extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
struct uvc_buffer *buf); struct uvc_buffer *buf);
extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue, extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue,
struct file *file, poll_table *wait); struct file *file, poll_table *wait);
extern int uvc_queue_allocated(struct uvc_video_queue *queue);
static inline int uvc_queue_streaming(struct uvc_video_queue *queue) static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
{ {
return queue->flags & UVC_QUEUE_STREAMING; return queue->flags & UVC_QUEUE_STREAMING;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment