Skip to content

usb: Propagate the result of submit_xfer. #1035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

hyx0329
Copy link

@hyx0329 hyx0329 commented Jul 30, 2025

The result is used in the hid keyboard module but was not actually propagated. With this result, the report double buffering will work correctly.

@hyx0329 hyx0329 force-pushed the propagate-usb-xfer-state branch from 3b8bad4 to 3a7b150 Compare July 30, 2025 15:01
@hyx0329 hyx0329 changed the title usb: propagate submit_xfer result usb: Propagate the result of submit_xfer. Jul 30, 2025
@Josverl
Copy link

Josverl commented Jul 31, 2025

Could you add a test to verify this in CI?

Or is this already covered by another test?

@dpgeorge
Copy link
Member

There is a comment in Interface.submit_xfer():

# If the function returns, the transfer is queued.

I guess that's either incorrect and should be changed, or is correct and then this PR is not needed.

@projectgus maybe we need your input here.

@projectgus
Copy link
Contributor

projectgus commented Aug 1, 2025

Hmm, yeah - the underlying machine.USBDevice can return False if the transfer fails to queue due to a DCD error. This is documented on Interface.submit_xfer() as being the third case where it can raise an exception, but the result isn't checked so it won't raise an exception (currently).

In general, submit_xfer() should only fail under "exceptional" circumstances (i.e. broken hardware or broken driver), so it probably is better to change hid.send_report() to ignore the submit_xfer() result and return True. Then also update Interface.submit_xfer() so it raises an exception if the lower layer returns False (i.e. make the behaviour the same as what is documented).

@hyx0329 Thanks for pointing this out and submitting the fix. Are you up for updating your PR along these lines?

hyx0329 added 2 commits August 1, 2025 13:05
So the behavior matches the comment.

Signed-off-by: Hyx <[email protected]>
This tells the caller that no error has occurred. The child classes can
use this state to do double buffering correctly.

If any fundamental error occurs in submit_xfer, the underlying code will
raise an exception.

Signed-off-by: Hyx <[email protected]>
@hyx0329 hyx0329 force-pushed the propagate-usb-xfer-state branch from 3a7b150 to 6e46847 Compare August 1, 2025 05:07
@hyx0329
Copy link
Author

hyx0329 commented Aug 1, 2025

I've updated the PR with the proposed changes. It should work now.

As to the test, I have no idea how to do it with software only. Core depends on machine.USBDevice.

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.

4 participants