yangsong8-a1 opened a new pull request, #22158: URL: https://github.com/apache/nuttx/pull/22158
## Summary The serial upper half calls `setup()` and `shutdown()` with `uart_spinlock()` held (since #21746). `usbhost_cdcacm` and `usbhost_ft232r` took `priv->lock` (a mutex) there, and `shutdown()` called `usbhost_destroy()` when the device had been unplugged while open. From reading the code, unplug-then-close was broken on its own too: `usbhost_destroy()` frees the class instance, which contains the `uart_dev_s` that `uart_close()` keeps using, and its `unregister_driver()` reaches `uart_unlink()`, which takes the `closelock` that `uart_close()` holds. Use the upper half's `release()` method instead: `setup()`/`shutdown()` only update `crefs` under the existing spinlock / critical section; `usbhost_disconnected()` unregisters the device at once (unless `usbhost_connect()` is running); `usbhost_release()` frees everything after the last close. ## Impact USB host CDC/ACM and FT232R serial devices. After an unplug the `/dev/ttyACMn` / `/dev/ttyUSBn` node is removed at once instead of at the last close. ## Testing Ubuntu 22.04, gcc 13.1.0, QEMU 6.2.0. - Build: `sim:usbhost` (CDC/ACM), `qemu-intel64:nsh` + xHCI PCI + `CONFIG_USBHOST_FT232R` (SMP=2 and SMP=n), no warnings. - Runtime, FT232R with QEMU `-device qemu-xhci -device usb-serial`: device enumerated as `/dev/ttyUSB0`; 40 `echo ... > /dev/ttyUSB0` (open, write, close) all reached the host chardev, SMP=2 and SMP=n, same as master. Not tested: the unplug path (QEMU `device_del` is not reported by the xHCI driver, on master either, so `usbhost_disconnected()` never runs); CDC/ACM at runtime; real hardware. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
