Skip to content

Fix vcam streaming lifecycle correctness in videobuf#48

Open
davidzwei wants to merge 2 commits into
sysprog21:masterfrom
davidzwei:davidzwei/fix-videobuf-streaming
Open

Fix vcam streaming lifecycle correctness in videobuf#48
davidzwei wants to merge 2 commits into
sysprog21:masterfrom
davidzwei:davidzwei/fix-videobuf-streaming

Conversation

@davidzwei
Copy link
Copy Markdown
Contributor

@davidzwei davidzwei commented Jun 2, 2026

Two correctness fixes in videobuf.c for the streaming lifecycle:

  • vcam_start_streaming(): kthread_create() returns ERR_PTR(-ENOMEM)
    on failure, not NULL. The previous !ptr check evaluates to false
    for any ERR_PTR value since it is a non-zero pointer, leaving
    sub_thr_id holding an invalid address. Replace with IS_ERR() and
    reset sub_thr_id to NULL on failure so vcam_stop_streaming()
    skips the kthread_stop() call safely.

  • vcam_stop_streaming(): vb2_buffer_done() must not be called in
    atomic context as it internally invokes wake_up() on the done wait
    queue. Use list_splice_init() to transfer all active buffers to a
    temporary local list in O(1) while holding the spinlock, then release
    the lock before iterating and calling vb2_buffer_done(). This also
    minimises the critical section length.


Summary by cubic

Fixes vcam streaming lifecycle issues in videobuf.c to avoid crashes and stuck buffers. Improves correctness when starting and stopping streaming.

  • Bug Fixes
    • Use IS_ERR() for kthread_create() and reset sub_thr_id to NULL on failure so vcam_stop_streaming() safely skips kthread_stop().
    • Move vb2_buffer_done() out of the spinlock: list_splice_init() active buffers to a temp list under lock, then complete them unlocked with VB2_BUF_STATE_ERROR.

Written for commit 10ead39. Summary will update on new commits.

Review in cubic

davidzwei added 2 commits June 2, 2026 23:42
kthread_create() returns ERR_PTR() on failure rather than NULL.

Replace the NULL check with IS_ERR() and propagate the error
code via PTR_ERR(). This prevents wake_up_process() from being
called on an invalid task pointer when thread creation fails.
vcam_stop_streaming() completes queued buffers while holding
out_q_slock with IRQs disabled. vb2_buffer_done() must not be
called in atomic context as it internally invokes wake_up()
on the done wait queue.

Move all active buffers to a temporary list under the spinlock
and release the lock before calling vb2_buffer_done(). This
ensures buffer completion is always invoked from a preemptible
context.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant