Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

media: vb2: drop wait_prepare/finish callbacks

Drop the wait_prepare/finish callbacks. Instead require that the vb2_queue
lock field is always set and use that lock when waiting for buffers to
arrive.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

authored by

Hans Verkuil and committed by
Mauro Carvalho Chehab
b70886ff d0730006

+15 -59
-2
Documentation/userspace-api/media/conf_nitpick.py
··· 42 42 ("c:func", "struct fd_set"), 43 43 ("c:func", "struct pollfd"), 44 44 ("c:func", "usb_make_path"), 45 - ("c:func", "wait_finish"), 46 - ("c:func", "wait_prepare"), 47 45 ("c:func", "write"), 48 46 49 47 ("c:type", "atomic_t"),
+10 -39
drivers/media/common/videobuf2/videobuf2-core.c
··· 605 605 */ 606 606 if (vb2_get_num_buffers(q)) { 607 607 bool unbalanced = q->cnt_start_streaming != q->cnt_stop_streaming || 608 - q->cnt_prepare_streaming != q->cnt_unprepare_streaming || 609 - q->cnt_wait_prepare != q->cnt_wait_finish; 608 + q->cnt_prepare_streaming != q->cnt_unprepare_streaming; 610 609 611 610 if (unbalanced) { 612 611 pr_info("unbalanced counters for queue %p:\n", q); ··· 616 617 if (q->cnt_prepare_streaming != q->cnt_unprepare_streaming) 617 618 pr_info(" prepare_streaming: %u unprepare_streaming: %u\n", 618 619 q->cnt_prepare_streaming, q->cnt_unprepare_streaming); 619 - if (q->cnt_wait_prepare != q->cnt_wait_finish) 620 - pr_info(" wait_prepare: %u wait_finish: %u\n", 621 - q->cnt_wait_prepare, q->cnt_wait_finish); 622 620 } 623 621 q->cnt_queue_setup = 0; 624 - q->cnt_wait_prepare = 0; 625 - q->cnt_wait_finish = 0; 626 622 q->cnt_prepare_streaming = 0; 627 623 q->cnt_start_streaming = 0; 628 624 q->cnt_stop_streaming = 0; ··· 2031 2037 * become ready or for streamoff. Driver's lock is released to 2032 2038 * allow streamoff or qbuf to be called while waiting. 2033 2039 */ 2034 - if (q->ops->wait_prepare) 2035 - call_void_qop(q, wait_prepare, q); 2036 - else if (q->lock) 2037 - mutex_unlock(q->lock); 2040 + mutex_unlock(q->lock); 2038 2041 2039 2042 /* 2040 2043 * All locks have been released, it is safe to sleep now. ··· 2041 2050 !list_empty(&q->done_list) || !q->streaming || 2042 2051 q->error); 2043 2052 2044 - if (q->ops->wait_finish) 2045 - call_void_qop(q, wait_finish, q); 2046 - else if (q->lock) 2047 - mutex_lock(q->lock); 2053 + mutex_lock(q->lock); 2048 2054 2049 2055 q->waiting_in_dqbuf = 0; 2050 2056 /* ··· 2641 2653 if (WARN_ON(q->min_reqbufs_allocation > q->max_num_buffers)) 2642 2654 return -EINVAL; 2643 2655 2644 - /* Either both or none are set */ 2645 - if (WARN_ON(!q->ops->wait_prepare ^ !q->ops->wait_finish)) 2646 - return -EINVAL; 2647 - 2648 - /* Warn if q->lock is NULL and no custom wait_prepare is provided */ 2649 - if (WARN_ON(!q->lock && !q->ops->wait_prepare)) 2656 + /* Warn if q->lock is NULL */ 2657 + if (WARN_ON(!q->lock)) 2650 2658 return -EINVAL; 2651 2659 2652 2660 INIT_LIST_HEAD(&q->queued_list); ··· 3204 3220 continue; 3205 3221 prequeue--; 3206 3222 } else { 3207 - if (!threadio->stop) { 3208 - if (q->ops->wait_finish) 3209 - call_void_qop(q, wait_finish, q); 3210 - else if (q->lock) 3211 - mutex_lock(q->lock); 3223 + mutex_lock(q->lock); 3224 + if (!threadio->stop) 3212 3225 ret = vb2_core_dqbuf(q, &index, NULL, 0); 3213 - if (q->ops->wait_prepare) 3214 - call_void_qop(q, wait_prepare, q); 3215 - else if (q->lock) 3216 - mutex_unlock(q->lock); 3217 - } 3226 + mutex_unlock(q->lock); 3218 3227 dprintk(q, 5, "file io: vb2_dqbuf result: %d\n", ret); 3219 3228 if (!ret) 3220 3229 vb = vb2_get_buffer(q, index); ··· 3222 3245 if (copy_timestamp) 3223 3246 vb->timestamp = ktime_get_ns(); 3224 3247 if (!threadio->stop) { 3225 - if (q->ops->wait_finish) 3226 - call_void_qop(q, wait_finish, q); 3227 - else if (q->lock) 3228 - mutex_lock(q->lock); 3248 + mutex_lock(q->lock); 3229 3249 ret = vb2_core_qbuf(q, vb, NULL, NULL); 3230 - if (q->ops->wait_prepare) 3231 - call_void_qop(q, wait_prepare, q); 3232 - else if (q->lock) 3233 - mutex_unlock(q->lock); 3250 + mutex_unlock(q->lock); 3234 3251 } 3235 3252 if (ret || threadio->stop) 3236 3253 break;
+5 -18
include/media/videobuf2-core.h
··· 351 351 * \*num_buffers are being allocated additionally to 352 352 * the buffers already allocated. If either \*num_planes 353 353 * or the requested sizes are invalid callback must return %-EINVAL. 354 - * @wait_prepare: release any locks taken while calling vb2 functions; 355 - * it is called before an ioctl needs to wait for a new 356 - * buffer to arrive; required to avoid a deadlock in 357 - * blocking access type. 358 - * @wait_finish: reacquire all locks released in the previous callback; 359 - * required to continue operation after sleeping while 360 - * waiting for a new buffer to arrive. 361 354 * @buf_out_validate: called when the output buffer is prepared or queued 362 355 * to a request; drivers can use this to validate 363 356 * userspace-provided information; this is required only ··· 428 435 int (*queue_setup)(struct vb2_queue *q, 429 436 unsigned int *num_buffers, unsigned int *num_planes, 430 437 unsigned int sizes[], struct device *alloc_devs[]); 431 - 432 - void (*wait_prepare)(struct vb2_queue *q); 433 - void (*wait_finish)(struct vb2_queue *q); 434 438 435 439 int (*buf_out_validate)(struct vb2_buffer *vb); 436 440 int (*buf_init)(struct vb2_buffer *vb); ··· 511 521 * @non_coherent_mem: when set queue will attempt to allocate buffers using 512 522 * non-coherent memory. 513 523 * @lock: pointer to a mutex that protects the &struct vb2_queue. The 514 - * driver can set this to a mutex to let the v4l2 core serialize 515 - * the queuing ioctls. If the driver wants to handle locking 516 - * itself, then this should be set to NULL. This lock is not used 517 - * by the videobuf2 core API. 524 + * driver must set this to a mutex to let the v4l2 core serialize 525 + * the queuing ioctls. This lock is used when waiting for a new 526 + * buffer to arrive: the lock is released, we wait for the new 527 + * buffer, and then retaken. 518 528 * @owner: The filehandle that 'owns' the buffers, i.e. the filehandle 519 529 * that called reqbufs, create_buffers or started fileio. 520 530 * This field is not used by the videobuf2 core API, but it allows ··· 670 680 * called. Used to check for unbalanced ops. 671 681 */ 672 682 u32 cnt_queue_setup; 673 - u32 cnt_wait_prepare; 674 - u32 cnt_wait_finish; 675 683 u32 cnt_prepare_streaming; 676 684 u32 cnt_start_streaming; 677 685 u32 cnt_stop_streaming; ··· 754 766 * @q: pointer to &struct vb2_queue with videobuf2 queue. 755 767 * 756 768 * This function will wait until all buffers that have been given to the driver 757 - * by &vb2_ops->buf_queue are given back to vb2 with vb2_buffer_done(). It 758 - * doesn't call &vb2_ops->wait_prepare/&vb2_ops->wait_finish pair. 769 + * by &vb2_ops->buf_queue are given back to vb2 with vb2_buffer_done(). 759 770 * It is intended to be called with all locks taken, for example from 760 771 * &vb2_ops->stop_streaming callback. 761 772 */