Re: [PATCH 3/3] [media] vb2: prevent drivers from requesting too many buffers/planes.

2011-04-03 Thread Hans Verkuil
On Monday, April 04, 2011 01:38:57 Pawel Osciak wrote:
> Add a sanity check to make sure drivers do not adjust the number of buffers
> or planes above the supported limit on reqbufs.
> 
> Signed-off-by: Pawel Osciak 
> ---
>  drivers/media/video/videobuf2-core.c |5 +
>  1 files changed, 5 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/media/video/videobuf2-core.c 
> b/drivers/media/video/videobuf2-core.c
> index 6698c77..6e69584 100644
> --- a/drivers/media/video/videobuf2-core.c
> +++ b/drivers/media/video/videobuf2-core.c
> @@ -529,6 +529,11 @@ int vb2_reqbufs(struct vb2_queue *q, struct 
> v4l2_requestbuffers *req)
>   if (ret)
>   return ret;
>  
> + /*
> +  * Make sure driver did not request more buffers/planes than we can 
> handle.
> +  */
> + BUG_ON (num_buffers > VIDEO_MAX_FRAME || num_planes > VIDEO_MAX_PLANES);
> +

I would make this a 'if' with a WARN_ON and error return. More debug-friendly.

Regards,

Hans

>   /* Finally, allocate buffers and video memory */
>   ret = __vb2_queue_alloc(q, req->memory, num_buffers, num_planes,
>   plane_sizes);
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/3] [media] vb2: prevent drivers from requesting too many buffers/planes.

2011-04-03 Thread Pawel Osciak
Add a sanity check to make sure drivers do not adjust the number of buffers
or planes above the supported limit on reqbufs.

Signed-off-by: Pawel Osciak 
---
 drivers/media/video/videobuf2-core.c |5 +
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/drivers/media/video/videobuf2-core.c 
b/drivers/media/video/videobuf2-core.c
index 6698c77..6e69584 100644
--- a/drivers/media/video/videobuf2-core.c
+++ b/drivers/media/video/videobuf2-core.c
@@ -529,6 +529,11 @@ int vb2_reqbufs(struct vb2_queue *q, struct 
v4l2_requestbuffers *req)
if (ret)
return ret;
 
+   /*
+* Make sure driver did not request more buffers/planes than we can 
handle.
+*/
+   BUG_ON (num_buffers > VIDEO_MAX_FRAME || num_planes > VIDEO_MAX_PLANES);
+
/* Finally, allocate buffers and video memory */
ret = __vb2_queue_alloc(q, req->memory, num_buffers, num_planes,
plane_sizes);
-- 
1.7.4.2

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html