Skip to contentSkip to conversation

mmc: sdhci: Setting the host->mrq to NULL before executing tuning

PATCH In review Chuansheng Liu 2 participants 2 messages Nov 5, 2013 – Nov 26, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: sdhci: Setting the host->mrq to NULL before executing tuning

In function sdhci_request(), it is possible to do the tuning execution like below:

sdhci_request() {
	spin_lock_irqsave(&host->lock, flags);
	host->mrq = mrq;
	...
	spin_unlock_irqrestore(&host->lock, flags);

<=== Here it is possible one pending finish_tasklet get running

     and it will operate the original mrq, and notified the mrq
     is done, and causes memory corruption.

	sdhci_execute_tuning(mmc, tuning_opcode);
	spin_lock_irqsave(&host->lock, flags);
	host->mrq = mrq;

...
}

In the above race place, the original mrq should not be finished wrongly, so here before unlock the spinlock, we need to set the host->mrq to NULL to avoid this case.

---
 drivers/mmc/host/sdhci.c |    7 +++++++
 1 file changed, 7 insertions(+)
drivers/mmc/host/sdhci.c +7 -0
index 7a7fb4f..c7a001a 100644
@@ -1391,6 +1391,13 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
 					mmc->card->type == MMC_TYPE_MMC ?
 					MMC_SEND_TUNING_BLOCK_HS200 :
 					MMC_SEND_TUNING_BLOCK;
+
+				/* Here we need to set the host->mrq to NULL,
+				 * in case the penging finish_tasklet
+				 * operates it wrongly.
+				 */
+				host->mrq = NULL;
+
 				spin_unlock_irqrestore(&host->lock, flags);
 				sdhci_execute_tuning(mmc, tuning_opcode);
 				spin_lock_irqsave(&host->lock, flags);
Signature · 1 line
1.7.9.5
#1 lore raw

Hi Chuansheng,

Quoted 36 lines · Chuansheng Liu

In function sdhci_request(), it is possible to do the tuning execution like below:

sdhci_request() {
	spin_lock_irqsave(&host->lock, flags);
	host->mrq = mrq;
	...
	spin_unlock_irqrestore(&host->lock, flags);

<=== Here it is possible one pending finish_tasklet get running

     and it will operate the original mrq, and notified the mrq
     is done, and causes memory corruption.

	sdhci_execute_tuning(mmc, tuning_opcode);
	spin_lock_irqsave(&host->lock, flags);
	host->mrq = mrq;

...
}

In the above race place, the original mrq should not be finished wrongly, so here before unlock the spinlock, we need to set the host->mrq to NULL to avoid this case.

---
 drivers/mmc/host/sdhci.c |    7 +++++++
 1 file changed, 7 insertions(+)
drivers/mmc/host/sdhci.c +0 -0
index 7a7fb4f..c7a001a 100644
@@ -1391,6 +1391,13 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
 					mmc->card->type == MMC_TYPE_MMC ?
 					MMC_SEND_TUNING_BLOCK_HS200 :
 					MMC_SEND_TUNING_BLOCK;

drivers/mmc/host/sdhci.c static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq) · line 1403

Quoted 10 lines
drivers/mmc/host/sdhci.c +7 -0
+
+				/* Here we need to set the host->mrq to NULL,
+				 * in case the penging finish_tasklet
+				 * operates it wrongly.
+				 */
+				host->mrq = NULL;
+
 				spin_unlock_irqrestore(&host->lock, flags);
 				sdhci_execute_tuning(mmc, tuning_opcode);
 				spin_lock_irqsave(&host->lock, flags);

Thanks, pushed to mmc-next for 3.14.

- Chris.

Signature · 1 line
Chris Ball   <[email protected]>   <http://printf.net/>