Swatantra-66 opened a new pull request, #22495:
URL: https://github.com/apache/nuttx/pull/22495

   ## 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.
   ```
   


-- 
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]

Reply via email to