-
Notifications
You must be signed in to change notification settings - Fork 37
fix(dcd): Fixed race condition on device disconnect #55
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
Conversation
LGTM. |
I think that for better compatibility with the upstream, we need to provide this mechanism in the Otherwise we just break all the builds for other controllers family which potentially will lead to difficulties during next synchronizations. |
e9ba17b
to
fa392ab
Compare
TinyUSB does not provide any locking means to protect the DCD variables. This can lead to race conditions when the user is trying to submit a transfer while the device is being disconnected. This can cause the device to be in an inconsistent state, leading to a crash or undefined behavior. This commit adds a spin-lock to protect the DCD variables during device disconnect. Closes espressif/esp-idf#9691 Also reported in espressif/esp-usb#131
fa392ab
to
d4a39f5
Compare
@roma-jam Thank you for the review! I added new file |
@roma-jam do you agree with the changes now? can we merge and release? |
@tore-espressif give me a moment, I want to check it on a hardware. |
@tore-espressif Unfortunately, I'm not able to reproduce the problem neither with May I ask you to share the log, how the application handled the situation, while we |
The bug can be 100% reproduced in |
but only in espressif/esp-usb#131, not in master branch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing: is there could be a possible situation when GINTSTS_USBRST
and GINTSTS_OEPINT
or GINTSTS_IEPINT
will be set in the same time, we could get the division by zero again.
Maybe we need to cover all the calls of edpt_schedule_packets()
in this case to prevent such logic scenario.
Otherwise, LGTM.
I see. However, practically, having both Rest and EP interrupt at the same time should never happen if we handle interrupts reasonably fast... I'll merge as it is and will continue watching the long-term stability |
TinyUSB does not provide any locking means to protect the DCD variables. This can lead to race conditions when the user is trying to submit a transfer while the device is being disconnected. This can cause the device to be in an inconsistent state, leading to a crash or undefined behavior.
This commit adds a spin-lock to protect the DCD variables during device disconnect.