[transport] usb: Fix htool crash on USB disconnect#249
Open
wak-google wants to merge 1 commit intogoogle:mainfrom
Open
[transport] usb: Fix htool crash on USB disconnect#249wak-google wants to merge 1 commit intogoogle:mainfrom
wak-google wants to merge 1 commit intogoogle:mainfrom
Conversation
Previously, libhoth_usb_fifo_run_transfers() could return while one or more libusb transfers were still pending. This happened if the second transfer submission failed, or if the event handling loop was interrupted by a signal (e.g. SIGINT). When htool subsequently attempted to close and reopen the transport, it would call libusb_free_transfer() on these pending transfers, triggering an assertion failure in libusb: 'usbi_mutex_lock: Assertion pthread_mutex_lock(mutex) == 0 failed' This change ensures that: 1. All submitted transfers are completed (success, error, or cancel) before the function returns. 2. If a transfer submission fails, any other successfully submitted transfer is cancelled and waited for. 3. Signal interruptions do not cause an early return while transfers are pending. 4. Completion flags are correctly initialized on open. Verified on yutulis-ru4-bmc-01 with 1000 iterations of target reset spam without a crash. Signed-off-by: William A. Kennington III <wak@google.com>
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.
Previously, libhoth_usb_fifo_run_transfers() could return while one or more libusb transfers were still pending. This happened if the second transfer submission failed, or if the event handling loop was interrupted by a signal (e.g. SIGINT).
When htool subsequently attempted to close and reopen the transport, it would call libusb_free_transfer() on these pending transfers, triggering an assertion failure in libusb:
'usbi_mutex_lock: Assertion pthread_mutex_lock(mutex) == 0 failed'
This change ensures that:
Verified on yutulis-ru4-bmc-01 with 1000 iterations of target reset spam without a crash.