From 5cd2a1ae68561be79eabe417d32a6bbdb17641b6 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Thu, 13 Jun 2019 01:27:02 +0000 Subject: [PATCH] Merged in antmerlino/nuttx/mmcsd-bugfix (pull request #893) drivers/mmcsd: Fixes bug where thread gets deadlocked due to recursive call and addresses comment regarding events. When initializing the MMCSD, if we are being told there is a card, but we fail to initialize it, we should not re-register for an insertion event as this will immediately cause us to call in again. Instead, we should register for a removal event and wait for the card to be removed and re-inserted. Approved-by: Gregory Nutt --- drivers/mmcsd/mmcsd_sdio.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/mmcsd/mmcsd_sdio.c b/drivers/mmcsd/mmcsd_sdio.c index 74f7de76f34..2bb33fccd60 100644 --- a/drivers/mmcsd/mmcsd_sdio.c +++ b/drivers/mmcsd/mmcsd_sdio.c @@ -3094,9 +3094,6 @@ static int mmcsd_probe(FAR struct mmcsd_state_s *priv) if (ret != OK) { ferr("ERROR: Failed to initialize card: %d\n", ret); -#ifdef CONFIG_MMCSD_HAVE_CARDDETECT - SDIO_CALLBACKENABLE(priv->dev, SDIOMEDIA_INSERTED); -#endif } else { @@ -3130,22 +3127,25 @@ static int mmcsd_probe(FAR struct mmcsd_state_s *priv) finfo("Capacity: %lu Kbytes\n", (unsigned long)(priv->capacity / 1024)); priv->mediachanged = true; - -#ifdef CONFIG_MMCSD_HAVE_CARDDETECT - /* Set up to receive asynchronous, media removal events */ - - SDIO_CALLBACKENABLE(priv->dev, SDIOMEDIA_EJECTED); -#endif } - - /* REVISIT: There is a problem here. If mmcsd_initialize() returns a - * failure, then no events are initialized. - */ } /* In any event, we have probed this card */ priv->probed = true; + + /* Regardless of whether or not a card was successfully initialized, there + * is appartently a card inserted. If it wasn't successfully initialized, + * there's nothing we can do about it now. Perhaps it's a bad card? The best + * we can do is wait for the card to be ejected and re-inserted. Then we + * can try to initialize again. + */ + +#ifdef CONFIG_MMCSD_HAVE_CARDDETECT + /* Set up to receive asynchronous, media removal events */ + + SDIO_CALLBACKENABLE(priv->dev, SDIOMEDIA_EJECTED); +#endif } else {