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

   ## Summary
   
   Resolves #14594.
   
   In `esp32_txint()` (`arch/xtensa/src/esp32/esp32_serial.c`), when 
`CONFIG_SUPPRESS_SERIAL_INTS` was active, `spin_unlock_irqrestore(&priv->lock, 
flags)` was called inside the `if (enable)` block before invoking 
`uart_xmitchars(dev)`. The execution then exited the `if (enable)` block and 
hit an unconditional `spin_unlock_irqrestore(&priv->lock, flags)` at the bottom 
of the function, causing consecutive unlocks on the same lock (issue #14594).
   
   This PR restructures `esp32_txint()` so that:
   1. The spinlock is held across register manipulation in both `if (enable)` 
and `else` branches and released exactly once at the end of the critical 
section.
   2. Under `CONFIG_SUPPRESS_SERIAL_INTS`, `uart_xmitchars(dev)` is called 
safely after `priv->lock` is released, preventing recursive spinlock deadlocks 
when `uart_xmitchars` calls back into `txint(dev, false)`.
   3. Updated the comment to accurately document that `uart_xmitchars()` runs 
after the spinlock is released.
   
   ## Impact
   - **ESP32 SMP & Debugging**: Prevents kernel panics and CPU interrupt state 
corruption caused by unlocking an already-unlocked spinlock.
   - **Concurrency**: Eliminates deadlock risk during recursive upper-half TX 
character processing.
   
   ## Testing
   - Verified with `./tools/checkpatch.sh -u HEAD` (0 errors, 0 warnings).
   - Verified with `./tools/nxstyle` on `arch/xtensa/src/esp32/esp32_serial.c` 
(0 errors, 0 warnings).
   


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