Skip to content

reject format changes while buffers are allocated#53

Open
grawis wants to merge 1 commit into
sysprog21:masterfrom
grawis:fix-s-fmt-while-busy
Open

reject format changes while buffers are allocated#53
grawis wants to merge 1 commit into
sysprog21:masterfrom
grawis:fix-s-fmt-while-busy

Conversation

@grawis

@grawis grawis commented Jun 12, 2026

Copy link
Copy Markdown

Summary

Reject VIDIOC_S_FMT with EBUSY while videobuf2 buffers are allocated.

Previously, VIDIOC_S_FMT updated dev->output_format even when existing
buffers had been allocated using the previous format's sizeimage. This
could leave the current format and buffer sizes inconsistent, causing a
later VIDIOC_QBUF call to fail.

The change checks vb2_is_busy() before applying the new format. Applications
must release existing buffers with VIDIOC_REQBUFS count=0 before changing
the format.

Test results

Before:

Initial format: 640x480 YUYV, bytesperline=1280, sizeimage=614400
Allocated buffers: 3
Buffer 0 length: 614400
S_FMT after REQBUFS: succeeded
Current format: 640x480 RGB3, bytesperline=1920, sizeimage=921600
QBUF after S_FMT: failed: Invalid argument

After:

 Initial format: 640x480 YUYV, bytesperline=1280, sizeimage=614400
 Allocated buffers: 3
 Buffer 0 length: 614400
 S_FMT after REQBUFS: failed: Device or resource busy
 Current format: 640x480 YUYV, bytesperline=1280, sizeimage=614400
 QBUF after S_FMT: succeeded

V4L2 compliance:

Total: 50, Succeeded: 50, Failed: 0, Warnings: 0

Fixes #52


Summary by cubic

Reject VIDIOC_S_FMT while videobuf2 buffers are allocated, returning -EBUSY. This keeps the current format consistent with allocated buffer sizes and prevents VIDIOC_QBUF errors.

Applications must release buffers with VIDIOC_REQBUFS count=0 before changing the format.

Written for commit 9e4afcd. Summary will update on new commits.

Review in cubic

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

Copy link
Copy Markdown

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.

VIDIOC_S_FMT should return EBUSY after buffers are allocated

1 participant