From 6bdf4fce97f1b24c6cae7de1a0e2cbdce1e870ee Mon Sep 17 00:00:00 2001 From: "Bao D. Nguyen" Date: Fri, 22 Feb 2019 16:50:12 -0800 Subject: [PATCH] mmc: core: Fix error when SD card is removed The device reboots when the SD card is removed. This is because the host->claimer resource has been released earlier as part of the SD card removal process. When mmc_try_claim_host tries to check the host->claimer->task, it dereferences a NULL pointer. Change-Id: I8625b17e337248791de6fac2ba5b3a2d5e82894e Signed-off-by: Bao D. Nguyen --- drivers/mmc/core/core.c | 5 +++-- drivers/mmc/core/sd.c | 2 -- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index f50e922b3cd5..d637bea65eef 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -1787,12 +1787,13 @@ int mmc_try_claim_host(struct mmc_host *host, unsigned int delay_ms) unsigned long flags; int retry_cnt = delay_ms/10; bool pm = false; + struct task_struct *task = current; do { spin_lock_irqsave(&host->lock, flags); - if (!host->claimed || host->claimer->task == current) { + if (!host->claimed || mmc_ctx_matches(host, NULL, task)) { host->claimed = 1; - host->claimer->task = current; + mmc_ctx_set_claimer(host, NULL, task); host->claim_cnt += 1; claimed_host = 1; if (host->claim_cnt == 1) diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 6ef491b68e92..30d625cc9adf 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -1197,8 +1197,6 @@ static void mmc_sd_detect(struct mmc_host *host) return; } - mmc_get_card(host->card, NULL); - /* * Just check if our card has been removed. */