linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mmc: sdhci: Setting the host->mrq to NULL before executing tuning
@ 2013-11-05  6:52 Chuansheng Liu
  2013-11-26 22:50 ` Chris Ball
  0 siblings, 1 reply; 2+ messages in thread
From: Chuansheng Liu @ 2013-11-05  6:52 UTC (permalink / raw)
  To: cjb; +Cc: linux-mmc, linux-kernel, chuansheng.liu, chuanxiao.dong


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.

Signed-off-by: Liu, Chuansheng <chuansheng.liu@intel.com>
---
 drivers/mmc/host/sdhci.c |    7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 7a7fb4f..c7a001a 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -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);
-- 
1.7.9.5




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mmc: sdhci: Setting the host->mrq to NULL before executing tuning
  2013-11-05  6:52 [PATCH] mmc: sdhci: Setting the host->mrq to NULL before executing tuning Chuansheng Liu
@ 2013-11-26 22:50 ` Chris Ball
  0 siblings, 0 replies; 2+ messages in thread
From: Chris Ball @ 2013-11-26 22:50 UTC (permalink / raw)
  To: Chuansheng Liu; +Cc: linux-mmc, linux-kernel, chuanxiao.dong

Hi Chuansheng,

On Tue, Nov 05 2013, Chuansheng Liu wrote:
> 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.
>
> Signed-off-by: Liu, Chuansheng <chuansheng.liu@intel.com>
> ---
>  drivers/mmc/host/sdhci.c |    7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
> index 7a7fb4f..c7a001a 100644
> --- a/drivers/mmc/host/sdhci.c
> +++ b/drivers/mmc/host/sdhci.c
> @@ -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);

Thanks, pushed to mmc-next for 3.14.

- Chris.
-- 
Chris Ball   <cjb@laptop.org>   <http://printf.net/>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-11-26 22:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-05  6:52 [PATCH] mmc: sdhci: Setting the host->mrq to NULL before executing tuning Chuansheng Liu
2013-11-26 22:50 ` Chris Ball

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).