Fix thread safety, races, and correctness issues across drivers#639
Draft
HTRamsey wants to merge 1 commit intomik3y:masterfrom
Draft
Fix thread safety, races, and correctness issues across drivers#639HTRamsey wants to merge 1 commit intomik3y:masterfrom
HTRamsey wants to merge 1 commit intomik3y:masterfrom
Conversation
- volatile on dtr/rts in Ch34x, Cp21xx, CdcAcm, Ftdi drivers - volatile on mReadRequest, mStartuplatch in CommonUsbSerialPort/SIOM - volatile on mStopReadStatusThread, mReadStatusException in Prolific - fix readAsync TOCTOU: local capture + try-catch on re-queue during close - fix Prolific mReadStatusException double-read race - fix Prolific sign-extended version byte parsing - fix CdcAcm double releaseInterface in single-interface mode - add CdcAcm endpoint count guard before getEndpoint(0) - fix ChromeCcd hard-coded port count, use getInterfaceCount() - fix SIOM stop() to handle STARTING state - fix SIOM start() InterruptedException to clean up threads - fix baud rate typos in Ftdi and Prolific (to -> too) - make TAG static final in CdcAcm, GsmModem, Prolific, ChromeCcd - make Ch34x DEFAULT_BAUD_RATE static final - make GsmModem initGsmModem() void (unused return) - add driver class name to UsbSerialProber exception
Collaborator
|
looks AI generated. Any real issues you want to fix? |
Contributor
Author
|
Believe things like usage of RESET_PURGE_TX & RESET_HXN_TX_PIPE are backwards right? But yeah all the extra debugging stuff was AI added to help me resolve a couple issues, can remove all the debugging stuff if you want |
Collaborator
|
yes, PURGE constants look reversed, which also confused me when I took over the library, but DeviceTest.purgeHwBuffers() successfully tests the functionality so I kept as is. |
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.
Summary
Targeted fixes for thread safety, race conditions, error handling, and correctness issues across all drivers and utilities. No new APIs, no architectural changes.
Thread safety (
volatile)mReadRequest,DEBUG,breakConfig,mStatus,mDeviceType, latency timer fields accessed across threads without visibility guaranteesDEBUG,mReadTimeout,mWriteTimeout,mThreadPriority,mReadBuffer,mWriteBufferxonfieldCorrectness fixes
getStatus()validates exact return length, not just>= 0— prevents returning stale/zeroed data on partial transfermIsRestrictedPortassignmentinterrupt()beforejoin()on status thread — prevents indefinite hang if thread is blocked on USB transferBoolean.TRUE.equals(o)instead of(boolean)o— prevents NPE if probe method returns nullmReadRequestinreadAsync()before queueing;getSerial()throws if port not openError handling
catch(Exception ignored){}withLog.win all driver close paths — makes USB debugging possibletestConnectionerror message includes return code (rc=)Resource management
UsbRequest.close()on Android O+ (was only cancelling, not closing)Other
static finalon TAG and constant fields that were incorrectly instance-scopedLinkedList→ArrayListfor read queue (better random-access performance)Test plan
Log.wmessages appear in logcat during abnormal disconnect