usb: use usbstorage_register_callback to unregister
What changed, and why it matters
This commit changes how a USB storage callback is unregistered when a background task shuts down. Instead of directly clearing two internal variables while holding a mutex, the code now calls the existing registration function with NULL values. This is a cleanup/refactoring change that likely fixes a potential race condition or inconsistent state, but the diff alone does not show an exploitable vulnerability.
Treat as a low-risk hardening/correctness fix. Review usbstorage_register_callback to confirm it provides equivalent or stronger locking semantics, and verify no callers still perform open-coded unregistration. No urgent security response is indicated by this diff alone.
Security signals we found
Synchronization primitive change around callback unregistration
Replacement of open-coded pointer clearing with helper function
Potential race-condition hardening in USB mass-storage teardown
Evidence from the diff
In main/usbhmsc/usbhmsc.c, the usbstorage_task cleanup path previously took callback_mutex, set registered_callback and callback_ctx to NULL, then released the mutex. The patch replaces that inline sequence with a call to usbstorage_register_callback(NULL, NULL). That helper presumably performs the same mutex-protected update, possibly with additional bookkeeping. The change reduces duplicated logic and may prevent a window where the callback pointers could be left in an inconsistent state if the inline code path failed or was bypassed. No memory corruption, injection, or privilege-escalation path is visible from the diff.
Changed components
main/usbhmsc/usbhmsc.cusbstorage_taskusbstorage_register_callbackInspect captured patch +1 / −4
diff --git a/main/usbhmsc/usbhmsc.c b/main/usbhmsc/usbhmsc.c
index f06a66d..252895c 100644
--- a/main/usbhmsc/usbhmsc.c
+++ b/main/usbhmsc/usbhmsc.c
@@ -230,10 +230,7 @@ static void usbstorage_task(void* ignore)
}
}
}
- JADE_SEMAPHORE_TAKE(callback_mutex);
- registered_callback = NULL;
- callback_ctx = NULL;
- JADE_SEMAPHORE_GIVE(callback_mutex);
+ usbstorage_register_callback(NULL, NULL);
// This may fail if the user removes the device at the right time
if (requires_host_uninstall) {
Why this scored 32/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.