From: "Bao D. Nguyen" <nguyenb@xxxxxxxxxxx> Fix various trivial SD card issues. Signed-off-by: Bao D. Nguyen <nguyenb@xxxxxxxxxxxxxx> --- drivers/mmc/core/block.c | 4 ++-- drivers/mmc/core/bus.c | 13 +++++++++++++ drivers/mmc/core/core.c | 13 ++++++++----- drivers/mmc/core/sd.c | 9 ++++++--- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 95b41c0..200882d 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -653,13 +653,13 @@ static int mmc_blk_ioctl_cmd(struct mmc_blk_data *md, struct request *req; idata = mmc_blk_ioctl_copy_from_user(ic_ptr); - if (IS_ERR(idata)) + if (IS_ERR_OR_NULL(idata)) return PTR_ERR(idata); /* This will be NULL on non-RPMB ioctl():s */ idata->rpmb = rpmb; card = md->queue.card; - if (IS_ERR(card)) { + if (IS_ERR_OR_NULL(card)) { err = PTR_ERR(card); goto cmd_done; } diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c index 74de3f2..fb17d21 100644 --- a/drivers/mmc/core/bus.c +++ b/drivers/mmc/core/bus.c @@ -131,6 +131,16 @@ static void mmc_bus_shutdown(struct device *dev) struct mmc_host *host = card->host; int ret; + if (!drv) { + pr_debug("%s: %s: drv is NULL\n", dev_name(dev), __func__); + return; + } + + if (!card) { + pr_debug("%s: %s: card is NULL\n", dev_name(dev), __func__); + return; + } + if (dev->driver && drv->shutdown) drv->shutdown(card); @@ -247,12 +257,15 @@ void mmc_unregister_driver(struct mmc_driver *drv) static void mmc_release_card(struct device *dev) { struct mmc_card *card = mmc_dev_to_card(dev); + struct mmc_host *host = card->host; sdio_free_common_cis(card); kfree(card->info); kfree(card); + if (host) + host->card = NULL; } /* diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 38b0cec..13d496e 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -399,7 +399,7 @@ void mmc_wait_for_req_done(struct mmc_host *host, struct mmc_request *mrq) struct mmc_command *cmd; while (1) { - wait_for_completion(&mrq->completion); + wait_for_completion_io(&mrq->completion); cmd = mrq->cmd; @@ -666,6 +666,10 @@ void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card) { unsigned int mult; + if (!card) { + WARN_ON(1); + return; + } /* * SDIO cards only define an upper 1 s limit on access. */ @@ -2341,17 +2345,16 @@ void mmc_rescan(struct work_struct *work) void mmc_start_host(struct mmc_host *host) { + mmc_claim_host(host); host->f_init = max(freqs[0], host->f_min); host->rescan_disable = 0; host->ios.power_mode = MMC_POWER_UNDEFINED; - if (!(host->caps2 & MMC_CAP2_NO_PRESCAN_POWERUP)) { - mmc_claim_host(host); + if (!(host->caps2 & MMC_CAP2_NO_PRESCAN_POWERUP)) mmc_power_up(host, host->ocr_avail); - mmc_release_host(host); - } mmc_gpiod_request_cd_irq(host); + mmc_release_host(host); _mmc_detect_change(host, 0, false); } diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 5938caf..e163f0e 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -989,6 +989,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, err = mmc_send_relative_addr(host, &card->rca); if (err) goto free_card; + host->card = card; } if (!oldcard) { @@ -1090,13 +1091,13 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, goto free_card; } done: - host->card = card; return 0; free_card: - if (!oldcard) + if (!oldcard) { + host->card = NULL; mmc_remove_card(card); - + } return err; } @@ -1106,7 +1107,9 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, static void mmc_sd_remove(struct mmc_host *host) { mmc_remove_card(host->card); + mmc_claim_host(host); host->card = NULL; + mmc_release_host(host); } /* -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project