Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b1d6b5be authored by Veerabhadrarao Badiganti's avatar Veerabhadrarao Badiganti
Browse files

mmc: core: Retry claim host in mmc_sd_detect



Use mmc_try_claim_host with a timeout instead of mmc_claim_host in
mmc_sd_detect. This is to ensure that mmc rescan work item is doesn't
get blocked on claim_host for longer period.

In the pm_suspend path, we cancel the mmc_rescan work item.
If this work item is already scheduled, suspend would be blocked till
mmc_rescan gets finished. In case, mmc_rescan is blocked on claim_host
lock, pm_suspend could get blocked for longer period.  This can result
in momentary UI freeze since pm_suspend is blocked for longer duration.
This change is to prevent this scenario.

Change-Id: Ib93bae6745a153bad3579ae42f46c3c3a7c1b95a
Signed-off-by: default avatarVeerabhadrarao Badiganti <vbadigan@codeaurora.org>
parent 79551c4b
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -2005,6 +2005,38 @@ int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)

EXPORT_SYMBOL(__mmc_claim_host);

/**
 *     mmc_try_claim_host - try exclusively to claim a host
 *        and keep trying for given time, with a gap of 10ms
 *     @host: mmc host to claim
 *     @dealy_ms: delay in ms
 *
 *     Returns %1 if the host is claimed, %0 otherwise.
 */
int mmc_try_claim_host(struct mmc_host *host, unsigned int delay_ms)
{
	int claimed_host = 0;
	unsigned long flags;
	int retry_cnt = delay_ms/10;

	do {
		spin_lock_irqsave(&host->lock, flags);
		if (!host->claimed || host->claimer == current) {
			host->claimed = 1;
			host->claimer = current;
			host->claim_cnt += 1;
			claimed_host = 1;
		}
		spin_unlock_irqrestore(&host->lock, flags);
		if (!claimed_host)
			mmc_delay(10);
	} while (!claimed_host && retry_cnt--);
	if (host->ops->enable && claimed_host && host->claim_cnt == 1)
		host->ops->enable(host);
	return claimed_host;
}
EXPORT_SYMBOL(mmc_try_claim_host);

/**
 *	mmc_release_host - release a host
 *	@host: mmc host to release
+11 −1
Original line number Diff line number Diff line
@@ -1149,7 +1149,17 @@ static void mmc_sd_detect(struct mmc_host *host)
	BUG_ON(!host);
	BUG_ON(!host->card);

	mmc_get_card(host->card);
	/*
	 * Try to acquire claim host. If failed to get the lock in 2 sec,
	 * just return; This is to ensure that when this call is invoked
	 * due to pm_suspend, not to block suspend for longer duration.
	 */
	pm_runtime_get_sync(&host->card->dev);
	if (!mmc_try_claim_host(host, 2000)) {
		pm_runtime_mark_last_busy(&host->card->dev);
		pm_runtime_put_autosuspend(&host->card->dev);
		return;
	}

	/*
	 * Just check if our card has been removed.
+1 −0
Original line number Diff line number Diff line
@@ -199,6 +199,7 @@ extern unsigned int mmc_align_data_size(struct mmc_card *, unsigned int);

extern int __mmc_claim_host(struct mmc_host *host, atomic_t *abort);
extern void mmc_release_host(struct mmc_host *host);
extern int mmc_try_claim_host(struct mmc_host *host, unsigned int delay);

extern void mmc_get_card(struct mmc_card *card);
extern void mmc_put_card(struct mmc_card *card);