This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 5594c2e887 imx9/lpuart: Fix race condition / regression in imx9_txint
5594c2e887 is described below

commit 5594c2e8875730f2f65b9fab57806e4c3c046379
Author: Jukka Laitinen <jukka.laiti...@tii.ae>
AuthorDate: Tue Jul 1 14:44:42 2025 +0300

    imx9/lpuart: Fix race condition / regression in imx9_txint
    
    Commit 83a119160 fixed SMP by removing call to uart_xmitchars from inside 
spinlock.
    
    This only works for SMP, since uart_xmitchars has a lock only in SMP. In a 
single
    core configuration the function can be called in parallel from the interrupt
    handler and from the imx9_txint.
    
    Fix this by filling the uart buffers already before enabling the
    interrupt, this way it is not possible to get the function called in 
parallel
    for the same device.
    
    Signed-off-by: Jukka Laitinen <jukka.laiti...@tii.ae>
---
 arch/arm64/src/imx9/imx9_lpuart.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/arm64/src/imx9/imx9_lpuart.c 
b/arch/arm64/src/imx9/imx9_lpuart.c
index d656de14f8..497d73ca5c 100644
--- a/arch/arm64/src/imx9/imx9_lpuart.c
+++ b/arch/arm64/src/imx9/imx9_lpuart.c
@@ -2340,6 +2340,13 @@ static void imx9_txint(struct uart_dev_s *dev, bool 
enable)
   irqstate_t flags;
   uint32_t regval;
 
+#ifndef CONFIG_SUPPRESS_SERIAL_INTS
+  if (enable)
+    {
+      uart_xmitchars(dev);
+    }
+#endif
+
   /* Enable interrupt for TX complete */
 
   flags = spin_lock_irqsave(&priv->lock);
@@ -2359,13 +2366,6 @@ static void imx9_txint(struct uart_dev_s *dev, bool 
enable)
   regval |= priv->ie;
   imx9_serialout(priv, IMX9_LPUART_CTRL_OFFSET, regval);
   spin_unlock_irqrestore(&priv->lock, flags);
-
-#ifndef CONFIG_SUPPRESS_SERIAL_INTS
-  if (enable)
-    {
-      uart_xmitchars(dev);
-    }
-#endif
 }
 #endif
 

Reply via email to