mmc: dw_mmc: check card present before starting request
authorShawn Lin <shawn.lin@rock-chips.com>
Fri, 27 May 2016 07:42:35 +0000 (15:42 +0800)
committerHuang, Tao <huangtao@rock-chips.com>
Mon, 30 May 2016 09:35:10 +0000 (17:35 +0800)
The main reason to add this check is to avoid unnecessary
mmc_request like the on-going cmd and the corresponding sbc
if the card is removed. Although we have already checked this in
dw_mci_handle_cd for runtime usage of sd card and dw_mci_init_slot
for noremovable devices, but there is a timing gap before it really
calls dw_mci_get_cd as mmc_detect_change needs some delay here.

Another gain here is that we could save some checkings of card status
after sd card been removed.

Change-Id: Iea741c1c72985fbe078f48da3796bddcab816e66
Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
drivers/mmc/host/dw_mmc.c

index 763c38dfa8c1ba3fdd889ebbcca41b76b200c609..4f0543c045284f6df8ab054acf6b7a296ae5834b 100644 (file)
@@ -105,6 +105,7 @@ struct idmac_desc {
 static bool dw_mci_reset(struct dw_mci *host);
 static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset);
 static int dw_mci_card_busy(struct mmc_host *mmc);
+static int dw_mci_get_cd(struct mmc_host *mmc);
 
 #if defined(CONFIG_DEBUG_FS)
 static int dw_mci_req_show(struct seq_file *s, void *v)
@@ -1256,15 +1257,15 @@ static void dw_mci_request(struct mmc_host *mmc, struct mmc_request *mrq)
         * atomic, otherwise the card could be removed in between and the
         * request wouldn't fail until another card was inserted.
         */
-       spin_lock_bh(&host->lock);
 
-       if (!test_bit(DW_MMC_CARD_PRESENT, &slot->flags)) {
-               spin_unlock_bh(&host->lock);
+       if (!dw_mci_get_cd(mmc)) {
                mrq->cmd->error = -ENOMEDIUM;
                mmc_request_done(mmc, mrq);
                return;
        }
 
+       spin_lock_bh(&host->lock);
+
        dw_mci_queue_request(host, slot, mrq);
 
        spin_unlock_bh(&host->lock);