Skip to content

Commit

Permalink
media: videobuf2-core: update vb2_thread if wait_finish/prepare are NULL
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Hans Verkuil committed Oct 28, 2024
1 parent c9ec6f1 commit 1d8aaa8
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions drivers/media/common/videobuf2/videobuf2-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3218,10 +3218,17 @@ static int vb2_thread(void *data)
continue;
prequeue--;
} else {
call_void_qop(q, wait_finish, q);
if (!threadio->stop)
if (!threadio->stop) {
if (q->ops->wait_finish)
call_void_qop(q, wait_finish, q);
else if (q->lock)
mutex_lock(q->lock);
ret = vb2_core_dqbuf(q, &index, NULL, 0);
call_void_qop(q, wait_prepare, q);
if (q->ops->wait_prepare)
call_void_qop(q, wait_prepare, q);
else if (q->lock)
mutex_unlock(q->lock);
}
dprintk(q, 5, "file io: vb2_dqbuf result: %d\n", ret);
if (!ret)
vb = vb2_get_buffer(q, index);
Expand All @@ -3233,12 +3240,19 @@ static int vb2_thread(void *data)
if (vb->state != VB2_BUF_STATE_ERROR)
if (threadio->fnc(vb, threadio->priv))
break;
call_void_qop(q, wait_finish, q);
if (copy_timestamp)
vb->timestamp = ktime_get_ns();
if (!threadio->stop)
if (!threadio->stop) {
if (q->ops->wait_finish)
call_void_qop(q, wait_finish, q);
else if (q->lock)
mutex_lock(q->lock);
ret = vb2_core_qbuf(q, vb, NULL, NULL);
call_void_qop(q, wait_prepare, q);
if (q->ops->wait_prepare)
call_void_qop(q, wait_prepare, q);
else if (q->lock)
mutex_unlock(q->lock);
}
if (ret || threadio->stop)
break;
}
Expand Down

0 comments on commit 1d8aaa8

Please sign in to comment.