markson0304 opened a new issue, #22304:
URL: https://github.com/apache/nuttx/issues/22304
### Description / Steps to reproduce the issue
When `EP_SUBMIT()` on the bulk IN endpoint fails, cdcacm neither puts the
write container back on `priv->txfree` nor restores `priv->nwrq`, so every
failed submit leaks one write request. After `CONFIG_CDCACM_NWRREQS` failures
`nwrq` stays 0 and the TX path is dead: data written to `/dev/ttyACMx` stays in
the xmit buffer and never reaches the host.
In `cdcuart_dmasend()` (the default path, TXBUF enabled):
```c
wrcontainer = (FAR struct cdcacm_wrreq_s *)sq_remfirst(&priv->txfree);
req = wrcontainer->req;
priv->nwrq--;
...
ret = EP_SUBMIT(ep, req);
if (ret < 0)
{
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_SUBMITFAIL),
(uint16_t)-ret);
} /* wrcontainer is neither queued nor returned */
```
By inspection (not reproduced), the polling write path (the one that sets
`priv->ispolling`) has the same pattern: The `CONFIG_CDCACM_DISABLE_TXBUF` path
in `cdcacm_sndpacket()` keeps the container in `priv->wrcontainer`, so it does
not seem affected.
A failing `EP_SUBMIT()` is a legitimate result: several in-tree device
controller drivers return `-ESHUTDOWN` from `ep_submit` (e.g. no class driver
bound) or `-EBUSY` (endpoint stalled). The write completion path,
`cdcacm_wrcomplete()`, already handles `-ESHUTDOWN` correctly because it always
returns the container first, so the submit-failure path is just inconsistent
with it.
### Steps to reproduce
Found while bringing up a USB device controller driver whose `ep_submit`
returns `-ESHUTDOWN` while the endpoint is not configured. Linux host, CDC/ACM,
`CONFIG_CDCACM_NWRREQS=4`:
1. On the device, write continuously to `/dev/ttyACM0`, e.g. `dd
if=/dev/zero of=/dev/ttyACM0 bs=64 count=32768`.
2. While it runs, on the host send SET_CONFIGURATION(0) then (1):
`echo 0 > /sys/bus/usb/devices/<dev>/bConfigurationValue; sleep 1; echo 1
> /sys/bus/usb/devices/<dev>/bConfigurationValue`
3. Each cycle logs one `SUBMITFAIL` (value `0x6c` = `ESHUTDOWN`) from a
write that lands between the two requests.
4. After the 4th cycle, `echo X > /dev/ttyACM0` on the device no longer
reaches the host.
State read with a debugger at that point: the endpoint's request queue is
empty, the controller and its DMA are idle, cdcacm `nwrq == 0`, and the xmit
buffer still holds the 8 unsent bytes.
### Suggested fix
On `EP_SUBMIT()` failure, return the container and restore the count, as
`cdcacm_wrcomplete()` does:
```c
if (ret < 0)
{
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_SUBMITFAIL),
(uint16_t)-ret);
flags = enter_critical_section();
sq_addlast((FAR sq_entry_t *)wrcontainer, &priv->txfree);
priv->nwrq++;
leave_critical_section(flags);
}
```
and the same in the polling path before `return ret`.
Seen on 12.12. Not run on master, but this code is unchanged there as of
44c01c24d0 (2026-11-19).
### On which OS does this issue occur?
[OS: Linux]
### What is the version of your OS?
Ubuntu 26.04.1 LTS
### NuttX Version
12.12 (code unchanged on master 44c01c24d0)
### Issue Architecture
[Arch: all]
### Issue Area
[Area: Drivers]
### Host information
_No response_
### Verification
- [x] I have verified before submitting the report.
--
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]