Skip to content

Commit 1d8aaa8

Browse files
committed
media: videobuf2-core: update vb2_thread if wait_finish/prepare are NULL
The vb2_thread is used for DVB support. This will queue and dequeue buffers automatically. It calls wait_finish/prepare around vb2_core_dqbuf() and vb2_core_qbuf(), but that assumes all drivers have these ops set. But that will change due to commit 8878598 ("media: vb2: use lock if wait_prepare/finish are NULL"). So instead just check if the callback is available, and if not, use q->lock, just as __vb2_wait_for_done_vb() does. Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent c9ec6f1 commit 1d8aaa8

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

drivers/media/common/videobuf2/videobuf2-core.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3218,10 +3218,17 @@ static int vb2_thread(void *data)
32183218
continue;
32193219
prequeue--;
32203220
} else {
3221-
call_void_qop(q, wait_finish, q);
3222-
if (!threadio->stop)
3221+
if (!threadio->stop) {
3222+
if (q->ops->wait_finish)
3223+
call_void_qop(q, wait_finish, q);
3224+
else if (q->lock)
3225+
mutex_lock(q->lock);
32233226
ret = vb2_core_dqbuf(q, &index, NULL, 0);
3224-
call_void_qop(q, wait_prepare, q);
3227+
if (q->ops->wait_prepare)
3228+
call_void_qop(q, wait_prepare, q);
3229+
else if (q->lock)
3230+
mutex_unlock(q->lock);
3231+
}
32253232
dprintk(q, 5, "file io: vb2_dqbuf result: %d\n", ret);
32263233
if (!ret)
32273234
vb = vb2_get_buffer(q, index);
@@ -3233,12 +3240,19 @@ static int vb2_thread(void *data)
32333240
if (vb->state != VB2_BUF_STATE_ERROR)
32343241
if (threadio->fnc(vb, threadio->priv))
32353242
break;
3236-
call_void_qop(q, wait_finish, q);
32373243
if (copy_timestamp)
32383244
vb->timestamp = ktime_get_ns();
3239-
if (!threadio->stop)
3245+
if (!threadio->stop) {
3246+
if (q->ops->wait_finish)
3247+
call_void_qop(q, wait_finish, q);
3248+
else if (q->lock)
3249+
mutex_lock(q->lock);
32403250
ret = vb2_core_qbuf(q, vb, NULL, NULL);
3241-
call_void_qop(q, wait_prepare, q);
3251+
if (q->ops->wait_prepare)
3252+
call_void_qop(q, wait_prepare, q);
3253+
else if (q->lock)
3254+
mutex_unlock(q->lock);
3255+
}
32423256
if (ret || threadio->stop)
32433257
break;
32443258
}

0 commit comments

Comments
 (0)