fix(usb_host): Handle disconnect after device free#485
Open
igi540 wants to merge 1 commit into
Open
Conversation
af2beef to
b9eea2e
Compare
28445e2 to
81266f2
Compare
tore-espressif
approved these changes
Apr 29, 2026
Collaborator
tore-espressif
left a comment
There was a problem hiding this comment.
@igi540 Thank you for the well documented test case!
81266f2 to
8942736
Compare
There was a problem hiding this comment.
Pull request overview
Fixes a USB Host race where a root-port disconnect event can be handled after the device has already been freed/recycled, previously causing an abort when dev_tree_node_dev_gone() returned ESP_ERR_NOT_FOUND.
Changes:
- Treat
ESP_ERR_NOT_FOUNDfromdev_tree_node_dev_gone()as benign in the root-port disconnect path. - Add a no-client target regression test that reproduces disconnect-after-device-free timing.
- Document the fix in the USB Host component changelog.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
host/usb/src/hub.c |
Avoid aborting on ESP_ERR_NOT_FOUND when a disconnect arrives after the device node has already been recycled. |
host/usb/test/target_test/usb_host/main/test_usb_host_plugging.c |
Adds a no-client regression test covering the disconnect-after-free flow. |
host/usb/CHANGELOG.md |
Adds an Unreleased changelog entry documenting the race fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
When a device is freed while still connected, the recycle path can remove the dev tree node before the root port disconnect event is processed. Treat ESP_ERR_NOT_FOUND from dev_tree_node_dev_gone() as benign in that case. Add a regression test for the no-client path and document the fix in the changelog. Closes espressif/esp-idf#18366
8942736 to
7e9d13d
Compare
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.
Description
Fixes a USB Host race where a device can be freed while it is still physically connected. In this flow, the recycle path can remove the dev tree node before the root port disconnect event is handled, which made
dev_tree_node_dev_gone()returnESP_ERR_NOT_FOUNDand abort throughESP_ERROR_CHECK.This change treats
ESP_ERR_NOT_FOUNDas benign for that already-recycled disconnect path while keeping error checking for unexpected failures. It also adds a no-client regression test for disconnect-after-device-free and documents the fix in the changelog.Related
Closes espressif/esp-idf#18366
Closes IDFGH-17399
Testing
Test USB Host disconnect after device free (no client)