aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/v4l2-core
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2013-12-13 11:13:39 -0500
committerMauro Carvalho Chehab <m.chehab@samsung.com>2014-01-07 04:07:22 -0500
commit4138111a27859dcc56a5592c804dd16bb12a23d1 (patch)
treea20fbb0f7795f176648ebec165ad021046229c9f /drivers/media/v4l2-core
parentf103b5d64e12198343edc9ef7ad3eb4c0e826adf (diff)
[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: Hans Verkuil <hans.verkuil@cisco.com> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Diffstat (limited to 'drivers/media/v4l2-core')
-rw-r--r--drivers/media/v4l2-core/videobuf2-core.c118
1 files changed, 59 insertions, 59 deletions
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index 1c933c5092be..ca255da65108 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1284,14 +1284,8 @@ static int __buf_prepare(struct vb2_buffer *vb, const struct v4l2_buffer *b)
1284} 1284}
1285 1285
1286static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b, 1286static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b,
1287 const char *opname, 1287 const char *opname)
1288 int (*handler)(struct vb2_queue *,
1289 struct v4l2_buffer *,
1290 struct vb2_buffer *))
1291{ 1288{
1292 struct vb2_buffer *vb;
1293 int ret;
1294
1295 if (q->fileio) { 1289 if (q->fileio) {
1296 dprintk(1, "%s(): file io in progress\n", opname); 1290 dprintk(1, "%s(): file io in progress\n", opname);
1297 return -EBUSY; 1291 return -EBUSY;
@@ -1307,8 +1301,7 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b,
1307 return -EINVAL; 1301 return -EINVAL;
1308 } 1302 }
1309 1303
1310 vb = q->bufs[b->index]; 1304 if (q->bufs[b->index] == NULL) {
1311 if (NULL == vb) {
1312 /* Should never happen */ 1305 /* Should never happen */
1313 dprintk(1, "%s(): buffer is NULL\n", opname); 1306 dprintk(1, "%s(): buffer is NULL\n", opname);
1314 return -EINVAL; 1307 return -EINVAL;
@@ -1319,30 +1312,7 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b,
1319 return -EINVAL; 1312 return -EINVAL;
1320 } 1313 }
1321 1314
1322 ret = __verify_planes_array(vb, b); 1315 return __verify_planes_array(q->bufs[b->index], b);
1323 if (ret)
1324 return ret;
1325
1326 ret = handler(q, b, vb);
1327 if (!ret) {
1328 /* Fill buffer information for the userspace */
1329 __fill_v4l2_buffer(vb, b);
1330
1331 dprintk(1, "%s() of buffer %d succeeded\n", opname, vb->v4l2_buf.index);
1332 }
1333 return ret;
1334}
1335
1336static int __vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b,
1337 struct vb2_buffer *vb)
1338{
1339 if (vb->state != VB2_BUF_STATE_DEQUEUED) {
1340 dprintk(1, "%s(): invalid buffer state %d\n", __func__,
1341 vb->state);
1342 return -EINVAL;
1343 }
1344
1345 return __buf_prepare(vb, b);
1346} 1316}
1347 1317
1348/** 1318/**
@@ -1362,20 +1332,68 @@ static int __vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b,
1362 */ 1332 */
1363int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b) 1333int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b)
1364{ 1334{
1365 return vb2_queue_or_prepare_buf(q, b, "prepare_buf", __vb2_prepare_buf); 1335 int ret = vb2_queue_or_prepare_buf(q, b, "prepare_buf");
1336 struct vb2_buffer *vb;
1337
1338 if (ret)
1339 return ret;
1340
1341 vb = q->bufs[b->index];
1342 if (vb->state != VB2_BUF_STATE_DEQUEUED) {
1343 dprintk(1, "%s(): invalid buffer state %d\n", __func__,
1344 vb->state);
1345 return -EINVAL;
1346 }
1347
1348 ret = __buf_prepare(vb, b);
1349 if (!ret) {
1350 /* Fill buffer information for the userspace */
1351 __fill_v4l2_buffer(vb, b);
1352
1353 dprintk(1, "%s() of buffer %d succeeded\n", __func__, vb->v4l2_buf.index);
1354 }
1355 return ret;
1366} 1356}
1367EXPORT_SYMBOL_GPL(vb2_prepare_buf); 1357EXPORT_SYMBOL_GPL(vb2_prepare_buf);
1368 1358
1369static int __vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b, 1359/**
1370 struct vb2_buffer *vb) 1360 * vb2_qbuf() - Queue a buffer from userspace
1361 * @q: videobuf2 queue
1362 * @b: buffer structure passed from userspace to vidioc_qbuf handler
1363 * in driver
1364 *
1365 * Should be called from vidioc_qbuf ioctl handler of a driver.
1366 * This function:
1367 * 1) verifies the passed buffer,
1368 * 2) if necessary, calls buf_prepare callback in the driver (if provided), in
1369 * which driver-specific buffer initialization can be performed,
1370 * 3) if streaming is on, queues the buffer in driver by the means of buf_queue
1371 * callback for processing.
1372 *
1373 * The return values from this function are intended to be directly returned
1374 * from vidioc_qbuf handler in driver.
1375 */
1376int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
1371{ 1377{
1372 int ret; 1378 int ret = vb2_queue_or_prepare_buf(q, b, "qbuf");
1379 struct vb2_buffer *vb;
1380
1381 if (ret)
1382 return ret;
1383
1384 vb = q->bufs[b->index];
1385 if (vb->state != VB2_BUF_STATE_DEQUEUED) {
1386 dprintk(1, "%s(): invalid buffer state %d\n", __func__,
1387 vb->state);
1388 return -EINVAL;
1389 }
1373 1390
1374 switch (vb->state) { 1391 switch (vb->state) {
1375 case VB2_BUF_STATE_DEQUEUED: 1392 case VB2_BUF_STATE_DEQUEUED:
1376 ret = __buf_prepare(vb, b); 1393 ret = __buf_prepare(vb, b);
1377 if (ret) 1394 if (ret)
1378 return ret; 1395 return ret;
1396 break;
1379 case VB2_BUF_STATE_PREPARED: 1397 case VB2_BUF_STATE_PREPARED:
1380 break; 1398 break;
1381 case VB2_BUF_STATE_PREPARING: 1399 case VB2_BUF_STATE_PREPARING:
@@ -1400,29 +1418,11 @@ static int __vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b,
1400 if (q->streaming) 1418 if (q->streaming)
1401 __enqueue_in_driver(vb); 1419 __enqueue_in_driver(vb);
1402 1420
1403 return 0; 1421 /* Fill buffer information for the userspace */
1404} 1422 __fill_v4l2_buffer(vb, b);
1405 1423
1406/** 1424 dprintk(1, "%s() of buffer %d succeeded\n", __func__, vb->v4l2_buf.index);
1407 * vb2_qbuf() - Queue a buffer from userspace 1425 return 0;
1408 * @q: videobuf2 queue
1409 * @b: buffer structure passed from userspace to vidioc_qbuf handler
1410 * in driver
1411 *
1412 * Should be called from vidioc_qbuf ioctl handler of a driver.
1413 * This function:
1414 * 1) verifies the passed buffer,
1415 * 2) if necessary, calls buf_prepare callback in the driver (if provided), in
1416 * which driver-specific buffer initialization can be performed,
1417 * 3) if streaming is on, queues the buffer in driver by the means of buf_queue
1418 * callback for processing.
1419 *
1420 * The return values from this function are intended to be directly returned
1421 * from vidioc_qbuf handler in driver.
1422 */
1423int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
1424{
1425 return vb2_queue_or_prepare_buf(q, b, "qbuf", __vb2_qbuf);
1426} 1426}
1427EXPORT_SYMBOL_GPL(vb2_qbuf); 1427EXPORT_SYMBOL_GPL(vb2_qbuf);
1428 1428