Skip to content

usbdev/cdcacm: return write request to txfree when EP_SUBMIT fails - #22495

Merged
GUIDINGLI merged 1 commit into
apache:masterfrom
Swatantra-66:fix/cdcacm-wrreq-leak-on-submit-fail
Nov 28, 2026
Merged

GUIDINGLI merged 1 commit into
apache:masterfrom
Swatantra-66:fix/cdcacm-wrreq-leak-on-submit-fail

Conversation

@Swatantra-66

Copy link
Copy Markdown
Contributor

Summary

Fixes Issue #22304

When EP_SUBMIT() on bulk IN or interrupt IN fails (e.g. endpoint is shut down due to cable disconnection, host reconfiguration, or stalled endpoint returning -ESHUTDOWN or -EBUSY), the write request container is removed from priv->txfree and priv->nwrq is decremented, but never returned upon submission failure.

Because EP_SUBMIT() did not accept the request, the USB device controller will never invoke cdcacm_wrcomplete() for it. Consequently, each failed submit permanently leaks one write container and leaves priv->nwrq permanently decremented. After CONFIG_CDCACM_NWRREQS failures, priv->nwrq reaches 0, permanently stalling the transmit path on /dev/ttyACMx: data written to the device remains in the xmit buffer and never reaches the host.

This change returns wrcontainer to priv->txfree via sq_addlast() and restores priv->nwrq++ across all three submission error paths:

  • cdcuart_sendbuf (polling write path)
  • cdcacm_serialstate (serial state notification path)
  • cdcuart_dmasend (DMA/TXBUF write path)

Impact

  • Is new feature added? No.
  • User: Fixes permanent TX freeze on /dev/ttyACMx when USB cable is disconnected or reconfigured during active writes.
  • Build: Clean compilation across all architectures with CONFIG_CDCACM enabled.

Testing

Before and After Comparison

Execution Path Failure Condition Before (master) After (this patch)
cdcuart_dmasend (TXBUF enabled) EP_SUBMIT returns error (e.g. -ESHUTDOWN, -EBUSY) wrcontainer leaked, nwrq not restored; TX permanently stalls after NWRREQS failures wrcontainer returned to txfree, nwrq restored; TX recovers on next write
cdcuart_sendbuf (polling path) EP_SUBMIT returns error (e.g. -ESHUTDOWN, -EBUSY) wrcontainer leaked, nwrq not restored; TX permanently stalls after NWRREQS failures wrcontainer returned to txfree, nwrq restored; TX recovers on next write
cdcacm_serialstate (state notify) EP_SUBMIT returns error (e.g. -ESHUTDOWN, -EBUSY) wrcontainer leaked, nwrq not restored wrcontainer returned to txfree, nwrq restored

Verification Logs

Build verification:
Configuration: stm32f103-minimum:usbnsh (ARM Cortex-M3, arm-none-eabi-gcc 14.2.1)

$ ./tools/configure.sh -l stm32f103-minimum:usbnsh
Loaded configuration '.config'
Configuration saved to '.config'

$ make -j4
...
CC:  usbdev/cdcacm.c
CC:  usbdev/cdcacm_desc.c
...
LD: nuttx
Memory region         Used Size  Region Size  %age Used
           flash:       53472 B       128 KB     40.80%
            sram:        3896 B        20 KB     19.02%
CP: nuttx.bin

Code style check:

$ git diff --check
(clean, 0 warnings / errors)

$ ./tools/checkpatch.sh -u -m -
✔️ All checks pass.

When EP_SUBMIT() on bulk IN or interrupt IN fails (e.g. endpoint is shut
down due to cable disconnection, reconfiguration, or stalled endpoint
returning -ESHUTDOWN or -EBUSY), the write request container is removed
from priv->txfree and priv->nwrq is decremented, but never returned upon
submission failure.

Because EP_SUBMIT() did not accept the request, the USB device controller
will never invoke cdcacm_wrcomplete() for it. Consequently, each failed
submit permanently leaks one write container and leaves priv->nwrq
permanently decremented. After CONFIG_CDCACM_NWRREQS failures, priv->nwrq
reaches 0, permanently stalling the transmit path on /dev/ttyACMx.

This patch returns wrcontainer to priv->txfree via sq_addlast() and
restores priv->nwrq++ across all three submission error paths:
- cdcuart_sendbuf (polling write path)
- cdcacm_serialstate (serial state notification path)
- cdcuart_dmasend (DMA/TXBUF write path)

Fixes apache#22304

Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Swatantra Yadav <[email protected]>
@github-actions github-actions Bot added Size: XS The size of the change in this PR is very small Area: USB labels Nov 27, 2026
@github-actions

Copy link
Copy Markdown

@GUIDINGLI
GUIDINGLI merged commit 5b71685 into apache:master Nov 28, 2026
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: USB Size: XS The size of the change in this PR is very small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants