public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: linux-media@vger.kernel.org,
	Mauro Carvalho Chehab <mchehab@infradead.org>,
	Hans de Goede <hdegoede@redhat.com>,
	Guennadi Liakhovetski <g.liakhovetski@gmx.de>,
	Pawel Osciak <pawel@osciak.com>,
	Tomasz Stanislawski <t.stanislaws@samsung.com>,
	Hans Verkuil <hans.verkuil@cisco.com>
Subject: Re: [RFCv2 PATCH 23/34] vb2-core: refactor reqbufs/create_bufs.
Date: Wed, 27 Jun 2012 11:52:10 +0200	[thread overview]
Message-ID: <2768547.EFJTNiot7U@avalon> (raw)
In-Reply-To: <ba29d82aed900a60e0d5c170272bb28614d439ef.1340366355.git.hans.verkuil@cisco.com>

Hi Hans,

Thanks for the patch.

On Friday 22 June 2012 14:21:17 Hans Verkuil wrote:
> From: Hans Verkuil <hans.verkuil@cisco.com>
> 
> Split off the memory and type validation. This is done both from reqbufs and
> create_bufs, and will also be done by vb2 helpers in a later patch.
> 
> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> ---
>  drivers/media/video/videobuf2-core.c |  153 +++++++++++++++++--------------
>  1 file changed, 80 insertions(+), 73 deletions(-)
> 
> diff --git a/drivers/media/video/videobuf2-core.c
> b/drivers/media/video/videobuf2-core.c index 9d4e9ed..8486e33 100644
> --- a/drivers/media/video/videobuf2-core.c
> +++ b/drivers/media/video/videobuf2-core.c
> @@ -454,7 +454,53 @@ static int __verify_mmap_ops(struct vb2_queue *q)
>  }
> 
>  /**
> - * vb2_reqbufs() - Initiate streaming
> + * __verify_memory_type() - do basic checks for memory and type

I'd expand this comment a bit, as "basic checks" doesn't really tell much 
about the purpose of the checks. Maybe something like

"Check whether the memory type and buffer type passed to a buffer operation 
are compatible with the queue."

> + */
> +static int __verify_memory_type(struct vb2_queue *q, __u32 memory, __u32
> type)

What about using enum v4l2_memory and enum v4l2_buf_type instead of __u32 ?

> +{
> +	if (memory != V4L2_MEMORY_MMAP && memory != V4L2_MEMORY_USERPTR) {
> +		dprintk(1, "reqbufs: unsupported memory type\n");
> +		return -EINVAL;
> +	}
> +
> +	if (type != q->type) {
> +		dprintk(1, "reqbufs: requested type is incorrect\n");
> +		return -EINVAL;
> +	}
> +
> +	/*
> +	 * Make sure all the required memory ops for given memory type
> +	 * are available.
> +	 */
> +	if (memory == V4L2_MEMORY_MMAP && __verify_mmap_ops(q)) {
> +		dprintk(1, "reqbufs: MMAP for current setup unsupported\n");
> +		return -EINVAL;
> +	}
> +
> +	if (memory == V4L2_MEMORY_USERPTR && __verify_userptr_ops(q)) {
> +		dprintk(1, "reqbufs: USERPTR for current setup unsupported\n");
> +		return -EINVAL;
> +	}
> +
> +	/*
> +	 * Place the busy tests at the end: -EBUSY can be ignored when
> +	 * create_bufs is called with count == 0, but count == 0 should still
> +	 * do the memory and type validation.
> +	 */
> +	if (q->fileio) {
> +		dprintk(1, "reqbufs: file io in progress\n");
> +		return -EBUSY;
> +	}
> +
> +	if (q->streaming) {
> +		dprintk(1, "reqbufs: streaming active\n");
> +		return -EBUSY;
> +	}

create_bufs didn't check for q->streaming. Isn't it legal to add a buffer 
during streaming ?

> +	return 0;
> +}
> +
> +/**
> + * __reqbufs() - Initiate streaming
>   * @q:		videobuf2 queue
>   * @req:	struct passed from userspace to vidioc_reqbufs handler in driver
>   *
> @@ -476,45 +522,10 @@ static int __verify_mmap_ops(struct vb2_queue *q)
>   * The return values from this function are intended to be directly
> returned * from vidioc_reqbufs handler in driver.
>   */
> -int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
> +static int __reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
>  {
>  	unsigned int num_buffers, allocated_buffers, num_planes = 0;
> -	int ret = 0;
> -
> -	if (q->fileio) {
> -		dprintk(1, "reqbufs: file io in progress\n");
> -		return -EBUSY;
> -	}
> -
> -	if (req->memory != V4L2_MEMORY_MMAP
> -			&& req->memory != V4L2_MEMORY_USERPTR) {
> -		dprintk(1, "reqbufs: unsupported memory type\n");
> -		return -EINVAL;
> -	}
> -
> -	if (req->type != q->type) {
> -		dprintk(1, "reqbufs: requested type is incorrect\n");
> -		return -EINVAL;
> -	}
> -
> -	if (q->streaming) {
> -		dprintk(1, "reqbufs: streaming active\n");
> -		return -EBUSY;
> -	}
> -
> -	/*
> -	 * Make sure all the required memory ops for given memory type
> -	 * are available.
> -	 */
> -	if (req->memory == V4L2_MEMORY_MMAP && __verify_mmap_ops(q)) {
> -		dprintk(1, "reqbufs: MMAP for current setup unsupported\n");
> -		return -EINVAL;
> -	}
> -
> -	if (req->memory == V4L2_MEMORY_USERPTR && __verify_userptr_ops(q)) {
> -		dprintk(1, "reqbufs: USERPTR for current setup unsupported\n");
> -		return -EINVAL;
> -	}
> +	int ret;
> 
>  	if (req->count == 0 || q->num_buffers != 0 || q->memory != req->memory) {
>  		/*
> @@ -595,10 +606,23 @@ int vb2_reqbufs(struct vb2_queue *q, struct
> v4l2_requestbuffers *req)
> 
>  	return 0;
>  }
> +
> +/**
> + * vb2_reqbufs() - Wrapper for __reqbufs() that also verifies the memory
> and + * type values.
> + * @q:		videobuf2 queue
> + * @req:	struct passed from userspace to vidioc_reqbufs handler in driver
> + */
> +int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
> +{
> +	int ret = __verify_memory_type(q, req->memory, req->type);
> +
> +	return ret ? ret : __reqbufs(q, req);
> +}
>  EXPORT_SYMBOL_GPL(vb2_reqbufs);
> 
>  /**
> - * vb2_create_bufs() - Allocate buffers and any required auxiliary structs
> + * __create_bufs() - Allocate buffers and any required auxiliary structs
>   * @q:		videobuf2 queue
>   * @create:	creation parameters, passed from userspace to
> vidioc_create_bufs *		handler in driver
> @@ -612,40 +636,10 @@ EXPORT_SYMBOL_GPL(vb2_reqbufs);
>   * The return values from this function are intended to be directly
> returned * from vidioc_create_bufs handler in driver.
>   */
> -int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers
> *create) +static int __create_bufs(struct vb2_queue *q, struct
> v4l2_create_buffers *create) {
>  	unsigned int num_planes = 0, num_buffers, allocated_buffers;
> -	int ret = 0;
> -
> -	if (q->fileio) {
> -		dprintk(1, "%s(): file io in progress\n", __func__);
> -		return -EBUSY;
> -	}
> -
> -	if (create->memory != V4L2_MEMORY_MMAP
> -			&& create->memory != V4L2_MEMORY_USERPTR) {
> -		dprintk(1, "%s(): unsupported memory type\n", __func__);
> -		return -EINVAL;
> -	}
> -
> -	if (create->format.type != q->type) {
> -		dprintk(1, "%s(): requested type is incorrect\n", __func__);
> -		return -EINVAL;
> -	}
> -
> -	/*
> -	 * Make sure all the required memory ops for given memory type
> -	 * are available.
> -	 */
> -	if (create->memory == V4L2_MEMORY_MMAP && __verify_mmap_ops(q)) {
> -		dprintk(1, "%s(): MMAP for current setup unsupported\n", __func__);
> -		return -EINVAL;
> -	}
> -
> -	if (create->memory == V4L2_MEMORY_USERPTR && __verify_userptr_ops(q)) {
> -		dprintk(1, "%s(): USERPTR for current setup unsupported\n", 
__func__);
> -		return -EINVAL;
> -	}
> +	int ret;
> 
>  	if (q->num_buffers == VIDEO_MAX_FRAME) {
>  		dprintk(1, "%s(): maximum number of buffers already allocated\n",
> @@ -653,8 +647,6 @@ int vb2_create_bufs(struct vb2_queue *q, struct
> v4l2_create_buffers *create) return -ENOBUFS;
>  	}
> 
> -	create->index = q->num_buffers;
> -
>  	if (!q->num_buffers) {
>  		memset(q->plane_sizes, 0, sizeof(q->plane_sizes));
>  		memset(q->alloc_ctx, 0, sizeof(q->alloc_ctx));
> @@ -719,6 +711,21 @@ int vb2_create_bufs(struct vb2_queue *q, struct
> v4l2_create_buffers *create)
> 
>  	return 0;
>  }
> +
> +/**
> + * vb2_reqbufs() - Wrapper for __reqbufs() that also verifies the memory
> and + * type values.
> + * @q:		videobuf2 queue
> + * @create:	creation parameters, passed from userspace to
> vidioc_create_bufs + *		handler in driver
> + */
> +int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers
> *create) +{
> +	int ret = __verify_memory_type(q, create->memory, create->format.type);
> +
> +	create->index = q->num_buffers;

I think this changes the behaviour of create_bufs, it should thus belong to 
the next patch.

> +	return ret ? ret : __create_bufs(q, create);
> +}
>  EXPORT_SYMBOL_GPL(vb2_create_bufs);
> 
>  /**
-- 
Regards,

Laurent Pinchart


  reply	other threads:[~2012-06-27  9:52 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-22 12:20 [RFCv2 PATCH 00/34] Core and vb2 enhancements Hans Verkuil
2012-06-22 12:20 ` [RFCv2 PATCH 01/34] Regression fixes Hans Verkuil
2012-06-22 12:20   ` [RFCv2 PATCH 02/34] v4l2-ioctl.c: move a block of code down, no other changes Hans Verkuil
2012-06-22 12:20   ` [RFCv2 PATCH 03/34] v4l2-ioctl.c: introduce INFO_FL_CLEAR to replace switch Hans Verkuil
2012-06-22 12:20   ` [RFCv2 PATCH 04/34] v4l2-ioctl.c: v4l2-ioctl: add debug and callback/offset functionality Hans Verkuil
2012-06-22 12:20   ` [RFCv2 PATCH 05/34] v4l2-ioctl.c: remove an unnecessary #ifdef Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 06/34] v4l2-ioctl.c: use the new table for querycap and i/o ioctls Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 07/34] v4l2-ioctl.c: use the new table for priority ioctls Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 08/34] v4l2-ioctl.c: use the new table for format/framebuffer ioctls Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 09/34] v4l2-ioctl.c: use the new table for overlay/streamon/off ioctls Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 10/34] v4l2-ioctl.c: use the new table for std/tuner/modulator ioctls Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 11/34] v4l2-ioctl.c: use the new table for queuing/parm ioctls Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 12/34] v4l2-ioctl.c: use the new table for control ioctls Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 13/34] v4l2-ioctl.c: use the new table for selection ioctls Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 14/34] v4l2-ioctl.c: use the new table for compression ioctls Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 15/34] v4l2-ioctl.c: use the new table for debug ioctls Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 16/34] v4l2-ioctl.c: use the new table for preset/timings ioctls Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 17/34] v4l2-ioctl.c: use the new table for the remaining ioctls Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 18/34] v4l2-ioctl.c: finalize table conversion Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 19/34] v4l2-dev.c: add debug sysfs entry Hans Verkuil
2012-06-27  9:54     ` Laurent Pinchart
2012-06-27 10:38       ` Hans Verkuil
2012-06-27 10:52         ` Laurent Pinchart
2012-06-22 12:21   ` [RFCv2 PATCH 20/34] v4l2-ioctl: remove v4l_(i2c_)print_ioctl Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 21/34] ivtv: don't mess with vfd->debug Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 22/34] cx18: " Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 23/34] vb2-core: refactor reqbufs/create_bufs Hans Verkuil
2012-06-27  9:52     ` Laurent Pinchart [this message]
2012-06-27 10:37       ` Hans Verkuil
2012-06-27 10:49         ` Laurent Pinchart
2012-06-22 12:21   ` [RFCv2 PATCH 24/34] vb2-core: add support for count == 0 in create_bufs Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 25/34] Spec: document CREATE_BUFS behavior if count == 0 Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 26/34] v4l2-dev/ioctl.c: add vb2_queue support to video_device Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 27/34] videobuf2-core: add helper functions Hans Verkuil
2012-06-27  9:42     ` Laurent Pinchart
2012-06-27 10:31       ` Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 28/34] vivi: remove pointless g/s_std support Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 29/34] vivi: embed struct video_device instead of allocating it Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 30/34] vivi: use vb2 helper functions Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 31/34] vivi: add create_bufs/preparebuf support Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 32/34] v4l2-dev.c: also add debug support for the fops Hans Verkuil
2012-06-27  9:59     ` Laurent Pinchart
2012-06-27 10:44       ` Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 33/34] pwc: use the new vb2 helpers Hans Verkuil
2012-06-22 12:21   ` [RFCv2 PATCH 34/34] pwc: v4l2-compliance fixes Hans Verkuil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2768547.EFJTNiot7U@avalon \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=g.liakhovetski@gmx.de \
    --cc=hans.verkuil@cisco.com \
    --cc=hdegoede@redhat.com \
    --cc=hverkuil@xs4all.nl \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@infradead.org \
    --cc=pawel@osciak.com \
    --cc=t.stanislaws@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox