Re: What should CREATE_BUFS do if count == 0?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Hans

On Thu, 7 Jun 2012, Hans Verkuil wrote:

> Hi all,
> 
> I'm extending v4l2-compliance with support for VIDIOC_REQBUFS and VIDIOC_CREATE_BUFS,
> and I ran into an undefined issue: what happens if VIDIOC_CREATE_BUFS is called with
> count set to 0?
> 
> I think there should be a separate test for that. Right now queue_setup will receive
> a request for 0 buffers, and I don't know if drivers expect a zero value there.
> 
> I suggest that CREATE_BUFS with a count of 0 will only check whether memory and
> format.type are valid, and if they are it will just return 0 and do nothing.

Sounds good to me.

> Also note that this code in vb2_create_bufs is wrong:
> 
>         ret = __vb2_queue_alloc(q, create->memory, num_buffers,
>                                 num_planes);
>         if (ret < 0) {
>                 dprintk(1, "Memory allocation failed with error: %d\n", ret);
>                 return ret;
>         }
> 
> It should be:
> 
> 		if (ret == 0) {

Indeed you're right. But then the return above should be "return -ENOMEM," 
shouldn't it?

> 
> __vb2_queue_alloc() returns the number of buffers it managed to allocate,
> which is never < 0.
> 
> I propose to add the patch included below.
> 
> Comments are welcome!
> 
> Regards,
> 
> 	Hans
> 
> diff --git a/drivers/media/video/videobuf2-core.c b/drivers/media/video/videobuf2-core.c
> index a0702fd..01a8312 100644
> --- a/drivers/media/video/videobuf2-core.c
> +++ b/drivers/media/video/videobuf2-core.c
> @@ -647,6 +647,9 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create)
>  		return -EINVAL;
>  	}
>  
> +	if (create->count == 0)
> +		return 0;
> +
>  	if (q->num_buffers == VIDEO_MAX_FRAME) {
>  		dprintk(1, "%s(): maximum number of buffers already allocated\n",
>  			__func__);
> @@ -675,7 +678,7 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create)
>  	/* Finally, allocate buffers and video memory */
>  	ret = __vb2_queue_alloc(q, create->memory, num_buffers,
>  				num_planes);
> -	if (ret < 0) {
> +	if (ret == 0) {
>  		dprintk(1, "Memory allocation failed with error: %d\n", ret);
>  		return ret;

See above, should return an error code here.

>  	}
> 

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux