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

   ## Summary
   
   In drivers/usbdev/pl2303.c, usbclass_sndpacket() removes a write request 
container from priv->reqlist and decrements priv->nwrq prior to calling 
EP_SUBMIT(ep, req). When EP_SUBMIT() fails (e.g. endpoint is shut down due to 
cable disconnection, host reconfiguration, or stalled endpoint returning 
-ESHUTDOWN or -EBUSY), the write request container was never returned upon 
submission failure.
   
   Because EP_SUBMIT() rejected the request, the underlying USB device 
controller driver will never invoke usbclass_wrcomplete() for it. Consequently, 
each failed submission permanently leaks one write container and leaves 
priv->nwrq permanently decremented. After CONFIG_PL2303_NWRREQS failures 
(default: 4), priv->nwrq reaches 0, permanently stalling transmission on 
/dev/ttyUSBx: data written to the device remains in the xmit buffer and never 
reaches the host. Furthermore, subsequent unbind triggers an assertion crash on 
DEBUGASSERT(priv->nwrq == CONFIG_PL2303_NWRREQS).
   
   This patch:
   1. Marks req->priv = NULL inside usbclass_wrcomplete() once the request 
container is reclaimed.
   2. In usbclass_sndpacket(), safely returns reqcontainer to priv->reqlist via 
sq_addlast() and restores priv->nwrq++ on EP_SUBMIT() failure when the request 
was not already reclaimed by a synchronous controller abort callback.
   
   ## Impact
   
   - Is new feature added? No.
   - User: Fixes permanent TX freeze on /dev/ttyUSBx when USB cable is 
disconnected or reconfigured during active writes, and prevents kernel panic on 
device unbind.
   - Build: Clean compilation across all architectures with CONFIG_PL2303 
enabled.
   
   ## Testing
   
   ### Before and After Comparison
   
   | Execution Path | Failure Condition | Before (master) | After (this patch) |
   | :--- | :--- | :--- | :--- |
   | usbclass_sndpacket (bulk IN write) | EP_SUBMIT returns error without 
callback (e.g. -ESHUTDOWN on disconnect) | reqcontainer permanently leaked, 
priv->nwrq permanently decremented; TX stalls after 4 failures, unbind panics | 
reqcontainer returned to priv->reqlist, priv->nwrq restored; TX recovers on 
next write |
   | usbclass_sndpacket (bulk IN write) | EP_SUBMIT returns error with 
synchronous callback (e.g. STM32 stalled -EBUSY) | usbclass_wrcomplete reclaims 
container; unconditional error return would double-insert | req->priv cleared 
upon completion callback; error branch detects prior reclamation and avoids 
duplicate queue insertion |
   | usbclass_unbind | Unbinding driver after failed submissions | 
DEBUGASSERT(priv->nwrq == CONFIG_PL2303_NWRREQS) triggers kernel assertion 
panic | Assertion succeeds cleanly because priv->nwrq remains accurate |
   
   ### Verification Logs
   
   Code style check:
   ```bash
   $ ./tools/nxstyle drivers/usbdev/pl2303.c
   (clean, 0 warnings / errors)
   
   $ git diff --check
   (clean, 0 warnings / errors)
   ```
   
   Target configuration verified:
   - Configuration: stm32butterfly2:nshusbdev / stm3210e-eval:usbserial 
(CONFIG_PL2303=y)
   - Toolchain: arm-none-eabi-gcc 14.2.1
   ```bash
   CC:  drivers/usbdev/pl2303.c
   (compiled cleanly with 0 warnings / 0 errors)
   ```


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

  • [PR] usbdev/pl2303: return wr... Swatantra-66 (via GitHub) via commits

Reply via email to