diff options
author | Laurent Pinchart <laurent.pinchart@skynet.be> | 2009-06-04 08:26:39 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-06-16 18:07:30 -0400 |
commit | 23ff6043add670713bbf2f6ee5d520459cfdfae9 (patch) | |
tree | b275b1baf5e1f9940b27e388784ed999ab1c6e93 /drivers/media/video/uvc | |
parent | d732c44c1a4b54e3c59ad92069bc2fd848aca5f3 (diff) |
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: Laurent Pinchart <laurent.pinchart@skynet.be>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/uvc')
-rw-r--r-- | drivers/media/video/uvc/uvc_queue.c | 14 | ||||
-rw-r--r-- | drivers/media/video/uvc/uvc_v4l2.c | 2 | ||||
-rw-r--r-- | drivers/media/video/uvc/uvcvideo.h | 1 |
3 files changed, 16 insertions, 1 deletions
diff --git a/drivers/media/video/uvc/uvc_queue.c b/drivers/media/video/uvc/uvc_queue.c index 0155752e4a5a..f854698c4061 100644 --- a/drivers/media/video/uvc/uvc_queue.c +++ b/drivers/media/video/uvc/uvc_queue.c | |||
@@ -172,6 +172,20 @@ int uvc_free_buffers(struct uvc_video_queue *queue) | |||
172 | return 0; | 172 | return 0; |
173 | } | 173 | } |
174 | 174 | ||
175 | /* | ||
176 | * Check if buffers have been allocated. | ||
177 | */ | ||
178 | int uvc_queue_allocated(struct uvc_video_queue *queue) | ||
179 | { | ||
180 | int allocated; | ||
181 | |||
182 | mutex_lock(&queue->mutex); | ||
183 | allocated = queue->count != 0; | ||
184 | mutex_unlock(&queue->mutex); | ||
185 | |||
186 | return allocated; | ||
187 | } | ||
188 | |||
175 | static void __uvc_query_buffer(struct uvc_buffer *buf, | 189 | static void __uvc_query_buffer(struct uvc_buffer *buf, |
176 | struct v4l2_buffer *v4l2_buf) | 190 | struct v4l2_buffer *v4l2_buf) |
177 | { | 191 | { |
diff --git a/drivers/media/video/uvc/uvc_v4l2.c b/drivers/media/video/uvc/uvc_v4l2.c index 507542dcbdae..f8b94d608a10 100644 --- a/drivers/media/video/uvc/uvc_v4l2.c +++ b/drivers/media/video/uvc/uvc_v4l2.c | |||
@@ -251,7 +251,7 @@ static int uvc_v4l2_set_format(struct uvc_video_device *video, | |||
251 | if (fmt->type != video->streaming->type) | 251 | if (fmt->type != video->streaming->type) |
252 | return -EINVAL; | 252 | return -EINVAL; |
253 | 253 | ||
254 | if (uvc_queue_streaming(&video->queue)) | 254 | if (uvc_queue_allocated(&video->queue)) |
255 | return -EBUSY; | 255 | return -EBUSY; |
256 | 256 | ||
257 | ret = uvc_v4l2_try_format(video, fmt, &probe, &format, &frame); | 257 | ret = uvc_v4l2_try_format(video, fmt, &probe, &format, &frame); |
diff --git a/drivers/media/video/uvc/uvcvideo.h b/drivers/media/video/uvc/uvcvideo.h index f435e8eeccd2..3c78d3c1e4c0 100644 --- a/drivers/media/video/uvc/uvcvideo.h +++ b/drivers/media/video/uvc/uvcvideo.h | |||
@@ -747,6 +747,7 @@ extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, | |||
747 | struct uvc_buffer *buf); | 747 | struct uvc_buffer *buf); |
748 | extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue, | 748 | extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue, |
749 | struct file *file, poll_table *wait); | 749 | struct file *file, poll_table *wait); |
750 | extern int uvc_queue_allocated(struct uvc_video_queue *queue); | ||
750 | static inline int uvc_queue_streaming(struct uvc_video_queue *queue) | 751 | static inline int uvc_queue_streaming(struct uvc_video_queue *queue) |
751 | { | 752 | { |
752 | return queue->flags & UVC_QUEUE_STREAMING; | 753 | return queue->flags & UVC_QUEUE_STREAMING; |