Fix vcam streaming lifecycle correctness in videobuf#48
Open
davidzwei wants to merge 2 commits into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two correctness fixes in
videobuf.cfor the streaming lifecycle:vcam_start_streaming():kthread_create()returnsERR_PTR(-ENOMEM)on failure, not
NULL. The previous!ptrcheck evaluates tofalsefor any
ERR_PTRvalue since it is a non-zero pointer, leavingsub_thr_idholding an invalid address. Replace withIS_ERR()andreset
sub_thr_idtoNULLon failure sovcam_stop_streaming()skips the
kthread_stop()call safely.vcam_stop_streaming():vb2_buffer_done()must not be called inatomic context as it internally invokes
wake_up()on the done waitqueue. Use
list_splice_init()to transfer all active buffers to atemporary local list in O(1) while holding the spinlock, then release
the lock before iterating and calling
vb2_buffer_done(). This alsominimises the critical section length.
Summary by cubic
Fixes vcam streaming lifecycle issues in
videobuf.cto avoid crashes and stuck buffers. Improves correctness when starting and stopping streaming.IS_ERR()forkthread_create()and resetsub_thr_idtoNULLon failure sovcam_stop_streaming()safely skipskthread_stop().vb2_buffer_done()out of the spinlock:list_splice_init()active buffers to a temp list under lock, then complete them unlocked withVB2_BUF_STATE_ERROR.Written for commit 10ead39. Summary will update on new commits.