Repository navigation
[nrf fromtree] usb: host: fix control transfer ownership in usbh_req_… - #4607
Open
andu-nordic wants to merge 1 commit into
Open
andu-nordic wants to merge 1 commit into
andu-nordic wants to merge 1 commit into
Conversation
…setup usbh_req_setup() waits on a single global semaphore with no mutual exclusion, so two threads can be inside it at once: enumeration runs on the bus thread while the shell and class drivers call in from their own. The first completion wakes an arbitrary waiter, which then reads xfer->err on a transfer that has not finished. Serialize the request with a mutex so the semaphore has one owner at a time. Timing out also released the transfer while the controller still owned it. uhc_ep_dequeue() only requests cancellation: the transfer stays with the driver until it is returned through the completion callback, and the driver may still write into its buffer. Callers such as usbh_req_desc_dev() free that buffer as soon as usbh_req_setup() returns, so a cancelled transfer could land in a recycled net_buf. Wait for the completion callback before freeing, and drop the callback's -ECONNRESET path now that the caller always owns the transfer. Signed-off-by: Ofir Shemesh <ofirshemesh777@gmail.com> (cherry picked from commit 6862873ee28efc6bbac5553de365cd0d92d1b55f)
carlescufi
approved these changes
Oct 14, 2026
tmon-nordic
approved these changes
Oct 15, 2026
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.
…setup
usbh_req_setup() waits on a single global semaphore with no mutual exclusion, so two threads can be inside it at once: enumeration runs on the bus thread while the shell and class drivers call in from their own. The first completion wakes an arbitrary waiter, which then reads xfer->err on a transfer that has not finished. Serialize the request with a mutex so the semaphore has one owner at a time.
Timing out also released the transfer while the controller still owned it. uhc_ep_dequeue() only requests cancellation: the transfer stays with the driver until it is returned through the completion callback, and the driver may still write into its buffer. Callers such as usbh_req_desc_dev() free that buffer as soon as usbh_req_setup() returns, so a cancelled transfer could land in a recycled net_buf. Wait for the completion callback before freeing, and drop the callback's -ECONNRESET path now that the caller always owns the transfer.
Signed-off-by: Ofir Shemesh ofirshemesh777@gmail.com
(cherry picked from commit 6862873)