Fixes and improvements (#642)

This commit is contained in:
Shadowtrance
2026-08-31 07:10:52 +10:00
committed by GitHub
parent 7a81b525ed
commit d3656bcd3d
14 changed files with 344 additions and 73 deletions
@@ -187,11 +187,15 @@ static error_t msc_device_stop(struct Device* device) {
return ERROR_NONE;
}
tinyusb_msc_storage_deinit();
// Disconnect and fully stop the TinyUSB device task before freeing storage state: the task
// keeps servicing SCSI commands (Windows polls TEST UNIT READY continuously, even on an
// ejected-but-still-enumerated device) until tinyusb_driver_uninstall() actually stops it, so
// freeing first left tud_msc_*_cb() callbacks dereferencing an already-freed storage handle.
auto* controller = device_get_parent(device);
usb_device_controller_release(controller, USB_DEVICE_CLASS_MSC);
tinyusb_msc_storage_deinit();
ctx->storage_active = false;
ctx->mount_changed_cb = nullptr;
ctx->mount_changed_context = nullptr;