Skip to content

Fix read length handling#45

Merged
jserv merged 1 commit into
sysprog21:masterfrom
Shaoen-Lin:fix-control-read
Jun 2, 2026
Merged

Fix read length handling#45
jserv merged 1 commit into
sysprog21:masterfrom
Shaoen-Lin:fix-control-read

Conversation

@Shaoen-Lin
Copy link
Copy Markdown
Contributor

@Shaoen-Lin Shaoen-Lin commented Jun 1, 2026

Function control_read() uses strlen(str) as the source length, but replaces it with the user supplied length when the user buffer is larger. This makes copy_to_user() read past the end of the static string.

The callback also ignores the file offset, so repeated reads do not reach EOF as expected.

Use simple_read_from_buffer() to limit the copy to the requested count and update the offset consistently.


Summary by cubic

Fix control_read to cap read length and honor file offsets by using simple_read_from_buffer, preventing reads past the static string and making repeated reads reach EOF.

Written for commit 7bf0aba. Summary will update on new commits.

Review in cubic

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

Copy link
Copy Markdown
Collaborator

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Check https://cbea.ms/git-commit/ carefully and enforce the rules.

The read callback may copy more bytes than the static string contains
when the requested read length exceeds strlen(str). It also never
updates *offset, so readers such as cat do not observe EOF.

Use simple_read_from_buffer() to cap the read length and advance the
file offset correctly.

Signed-off-by: Shaoen-Lin <shaoen.lin92@gmail.com>
@Shaoen-Lin
Copy link
Copy Markdown
Contributor Author

I've modified my commit message.

test case to reproduce:

This test case verifies that reading /dev/vcamctl reaches EOF. Before
the fix, control_read() did not update the file offset, so readers such
as cat kept reading the same string until timeout.

sudo insmod ./vcam.ko
sudo timeout 2 cat /dev/vcamctl
echo $?
sudo rmmod vcam

output before fix:

124

output after fix:

Virtual V4L2 compatible camera device
0

@jserv jserv merged commit 8cb6067 into sysprog21:master Jun 2, 2026
2 checks passed
@jserv
Copy link
Copy Markdown
Collaborator

jserv commented Jun 2, 2026

Thank @Shaoen-Lin for contributing!

@Shaoen-Lin Shaoen-Lin deleted the fix-control-read branch June 2, 2026 07:19
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.

2 participants