From d570a93945950b301f9660b0088d9ce26368ae19 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Thu, 9 Feb 2023 11:31:38 -0800 Subject: [PATCH] mmcsd_sdio:Insure a error exiting via mmcsd_removed will not Hang system. mmcsd_removed will be called if the card is in invalid state. This can happen if the card is bad, or vibrations causes a power loss. mmcsd_removed resets: priv->capacity = 0; /* Capacity=0 sometimes means no media */ priv->blocksize = 0; priv->probed = false; priv->mediachanged = false; priv->wrbusy = false; priv->type = MMCSD_CARDTYPE_UNKNOWN; priv->rca = 0; priv->selblocklen = 0; priv->widebus = false; If blocksize is set to 0 will cause the log2 to result in an infinate loop in some drivers. IS_EMPTY will check for priv->type = MMCSD_CARDTYPE_UNKNOWN and return ENODEV. --- drivers/mmcsd/mmcsd_sdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mmcsd/mmcsd_sdio.c b/drivers/mmcsd/mmcsd_sdio.c index 4e4f0e22a1..f61b140271 100644 --- a/drivers/mmcsd/mmcsd_sdio.c +++ b/drivers/mmcsd/mmcsd_sdio.c @@ -1190,7 +1190,7 @@ static int mmcsd_transferready(FAR struct mmcsd_state_s *priv) /* First, check if the card has been removed. */ - if (!SDIO_PRESENT(priv->dev)) + if (IS_EMPTY(priv) || !SDIO_PRESENT(priv->dev)) { ferr("ERROR: Card has been removed\n"); return -ENODEV;