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

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

commit 062010c660c0af3115735332240c41b76d89affb
Author: chao.an <[email protected]>
AuthorDate: Mon Jan 10 23:07:04 2022 +0800

    driver/mmcsdio: do not hold the semaphore on interrupt context
    
    so we can do the full dump to mmc/sd card in the panic case
    
    Signed-off-by: chao.an <[email protected]>
---
 drivers/mmcsd/mmcsd_sdio.c | 47 ++++++++++++++++++++++++++--------------------
 1 file changed, 27 insertions(+), 20 deletions(-)

diff --git a/drivers/mmcsd/mmcsd_sdio.c b/drivers/mmcsd/mmcsd_sdio.c
index da9dfc3d41..c2c7f30fd9 100644
--- a/drivers/mmcsd/mmcsd_sdio.c
+++ b/drivers/mmcsd/mmcsd_sdio.c
@@ -145,10 +145,7 @@ struct mmcsd_state_s
 /* Misc Helpers *************************************************************/
 
 static int    mmcsd_takesem(FAR struct mmcsd_state_s *priv);
-
-#ifndef CONFIG_SDIO_MUXBUS
-#  define mmcsd_givesem(p) nxsem_post(&priv->sem);
-#endif
+static void   mmcsd_givesem(FAR struct mmcsd_state_s *priv);
 
 /* Command/response helpers *************************************************/
 
@@ -259,35 +256,45 @@ static int mmcsd_takesem(FAR struct mmcsd_state_s *priv)
    * waiting)
    */
 
-  ret = nxsem_wait_uninterruptible(&priv->sem);
-  if (ret < 0)
+  if (up_interrupt_context() == false)
     {
-      return ret;
-    }
+      ret = nxsem_wait_uninterruptible(&priv->sem);
+      if (ret < 0)
+        {
+          return ret;
+        }
 
-  /* Lock the bus if mutually exclusive access to the SDIO bus is required
-   * on this platform.
-   */
+      /* Lock the bus if mutually exclusive access to the
+       * SDIO bus is required on this platform.
+       */
 
 #ifdef CONFIG_SDIO_MUXBUS
-  SDIO_LOCK(priv->dev, TRUE);
+      SDIO_LOCK(priv->dev, TRUE);
 #endif
+    }
+  else
+    {
+      ret = OK;
+    }
 
   return ret;
 }
 
-#ifdef CONFIG_SDIO_MUXBUS
 static void mmcsd_givesem(FAR struct mmcsd_state_s *priv)
 {
-  /* Release the SDIO bus lock, then the MMC/SD driver semaphore in the
-   * opposite order that they were taken to assure that no deadlock
-   * conditions will arise.
-   */
+  if (up_interrupt_context() == false)
+    {
+      /* Release the SDIO bus lock, then the MMC/SD driver semaphore in the
+       * opposite order that they were taken to assure that no deadlock
+       * conditions will arise.
+       */
 
-  SDIO_LOCK(priv->dev, FALSE);
-  nxsem_post(&priv->sem);
-}
+#ifdef CONFIG_SDIO_MUXBUS
+      SDIO_LOCK(priv->dev, FALSE);
 #endif
+      nxsem_post(&priv->sem);
+    }
+}
 
 /****************************************************************************
  * Command/Response Helpers

Reply via email to