Commit 4138111a authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

[media] vb2: simplify qbuf/prepare_buf by removing callback

The callback used to merge the common code of the qbuf/prepare_buf
code can be removed now that the mmap_sem handling is pushed down to
__buf_prepare(). This makes the code more readable.
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Acked-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarMauro Carvalho Chehab <m.chehab@samsung.com>
parent f103b5d6
...@@ -1284,14 +1284,8 @@ static int __buf_prepare(struct vb2_buffer *vb, const struct v4l2_buffer *b) ...@@ -1284,14 +1284,8 @@ static int __buf_prepare(struct vb2_buffer *vb, const struct v4l2_buffer *b)
} }
static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b, static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b,
const char *opname, const char *opname)
int (*handler)(struct vb2_queue *,
struct v4l2_buffer *,
struct vb2_buffer *))
{ {
struct vb2_buffer *vb;
int ret;
if (q->fileio) { if (q->fileio) {
dprintk(1, "%s(): file io in progress\n", opname); dprintk(1, "%s(): file io in progress\n", opname);
return -EBUSY; return -EBUSY;
...@@ -1307,8 +1301,7 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b, ...@@ -1307,8 +1301,7 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b,
return -EINVAL; return -EINVAL;
} }
vb = q->bufs[b->index]; if (q->bufs[b->index] == NULL) {
if (NULL == vb) {
/* Should never happen */ /* Should never happen */
dprintk(1, "%s(): buffer is NULL\n", opname); dprintk(1, "%s(): buffer is NULL\n", opname);
return -EINVAL; return -EINVAL;
...@@ -1319,30 +1312,7 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b, ...@@ -1319,30 +1312,7 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b,
return -EINVAL; return -EINVAL;
} }
ret = __verify_planes_array(vb, b); return __verify_planes_array(q->bufs[b->index], b);
if (ret)
return ret;
ret = handler(q, b, vb);
if (!ret) {
/* Fill buffer information for the userspace */
__fill_v4l2_buffer(vb, b);
dprintk(1, "%s() of buffer %d succeeded\n", opname, vb->v4l2_buf.index);
}
return ret;
}
static int __vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b,
struct vb2_buffer *vb)
{
if (vb->state != VB2_BUF_STATE_DEQUEUED) {
dprintk(1, "%s(): invalid buffer state %d\n", __func__,
vb->state);
return -EINVAL;
}
return __buf_prepare(vb, b);
} }
/** /**
...@@ -1362,20 +1332,68 @@ static int __vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b, ...@@ -1362,20 +1332,68 @@ static int __vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b,
*/ */
int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b) int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b)
{ {
return vb2_queue_or_prepare_buf(q, b, "prepare_buf", __vb2_prepare_buf); int ret = vb2_queue_or_prepare_buf(q, b, "prepare_buf");
struct vb2_buffer *vb;
if (ret)
return ret;
vb = q->bufs[b->index];
if (vb->state != VB2_BUF_STATE_DEQUEUED) {
dprintk(1, "%s(): invalid buffer state %d\n", __func__,
vb->state);
return -EINVAL;
}
ret = __buf_prepare(vb, b);
if (!ret) {
/* Fill buffer information for the userspace */
__fill_v4l2_buffer(vb, b);
dprintk(1, "%s() of buffer %d succeeded\n", __func__, vb->v4l2_buf.index);
}
return ret;
} }
EXPORT_SYMBOL_GPL(vb2_prepare_buf); EXPORT_SYMBOL_GPL(vb2_prepare_buf);
static int __vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b, /**
struct vb2_buffer *vb) * vb2_qbuf() - Queue a buffer from userspace
* @q: videobuf2 queue
* @b: buffer structure passed from userspace to vidioc_qbuf handler
* in driver
*
* Should be called from vidioc_qbuf ioctl handler of a driver.
* This function:
* 1) verifies the passed buffer,
* 2) if necessary, calls buf_prepare callback in the driver (if provided), in
* which driver-specific buffer initialization can be performed,
* 3) if streaming is on, queues the buffer in driver by the means of buf_queue
* callback for processing.
*
* The return values from this function are intended to be directly returned
* from vidioc_qbuf handler in driver.
*/
int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
{ {
int ret; int ret = vb2_queue_or_prepare_buf(q, b, "qbuf");
struct vb2_buffer *vb;
if (ret)
return ret;
vb = q->bufs[b->index];
if (vb->state != VB2_BUF_STATE_DEQUEUED) {
dprintk(1, "%s(): invalid buffer state %d\n", __func__,
vb->state);
return -EINVAL;
}
switch (vb->state) { switch (vb->state) {
case VB2_BUF_STATE_DEQUEUED: case VB2_BUF_STATE_DEQUEUED:
ret = __buf_prepare(vb, b); ret = __buf_prepare(vb, b);
if (ret) if (ret)
return ret; return ret;
break;
case VB2_BUF_STATE_PREPARED: case VB2_BUF_STATE_PREPARED:
break; break;
case VB2_BUF_STATE_PREPARING: case VB2_BUF_STATE_PREPARING:
...@@ -1400,29 +1418,11 @@ static int __vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b, ...@@ -1400,29 +1418,11 @@ static int __vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b,
if (q->streaming) if (q->streaming)
__enqueue_in_driver(vb); __enqueue_in_driver(vb);
return 0; /* Fill buffer information for the userspace */
} __fill_v4l2_buffer(vb, b);
/** dprintk(1, "%s() of buffer %d succeeded\n", __func__, vb->v4l2_buf.index);
* vb2_qbuf() - Queue a buffer from userspace return 0;
* @q: videobuf2 queue
* @b: buffer structure passed from userspace to vidioc_qbuf handler
* in driver
*
* Should be called from vidioc_qbuf ioctl handler of a driver.
* This function:
* 1) verifies the passed buffer,
* 2) if necessary, calls buf_prepare callback in the driver (if provided), in
* which driver-specific buffer initialization can be performed,
* 3) if streaming is on, queues the buffer in driver by the means of buf_queue
* callback for processing.
*
* The return values from this function are intended to be directly returned
* from vidioc_qbuf handler in driver.
*/
int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
{
return vb2_queue_or_prepare_buf(q, b, "qbuf", __vb2_qbuf);
} }
EXPORT_SYMBOL_GPL(vb2_qbuf); EXPORT_SYMBOL_GPL(vb2_qbuf);
......
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