All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mmc: sdhci: Clear unused bounce buffer at DMA mmap error path
@ 2021-06-11  9:03 Takashi Iwai
  2021-06-11  9:56 ` Adrian Hunter
  0 siblings, 1 reply; 3+ messages in thread
From: Takashi Iwai @ 2021-06-11  9:03 UTC (permalink / raw)
  To: Adrian Hunter; +Cc: Ulf Hansson, linux-mmc, linux-kernel

When DMA-mapping of the bounce buffer fails, the driver tries to fall
back, but it leaves the allocated host->bounce_buffer although its
size is zero.  Later on, the driver checks the use of bounce buffer
with host->bounce_buffer pointer, and it tries to use the buffer
incorrectly, resulting in Oops.

This patch clears the release the unused buffer and clears the
bounce_buffer pointer for addressing the problem.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 drivers/mmc/host/sdhci.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index bf238ade1602..5f467b98ca88 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -4072,9 +4072,13 @@ static void sdhci_allocate_bounce_buffer(struct sdhci_host *host)
 					   bounce_size,
 					   DMA_BIDIRECTIONAL);
 	ret = dma_mapping_error(mmc_dev(mmc), host->bounce_addr);
-	if (ret)
+	if (ret) {
+		devm_kfree(mmc->parent, host->bounce_buffer);
+		host->bounce_buffer = NULL;
 		/* Again fall back to max_segs == 1 */
 		return;
+	}
+
 	host->bounce_buffer_size = bounce_size;
 
 	/* Lie about this since we're bouncing */
-- 
2.26.2


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

* Re: [PATCH] mmc: sdhci: Clear unused bounce buffer at DMA mmap error path
  2021-06-11  9:03 [PATCH] mmc: sdhci: Clear unused bounce buffer at DMA mmap error path Takashi Iwai
@ 2021-06-11  9:56 ` Adrian Hunter
  2021-06-11 10:06   ` Takashi Iwai
  0 siblings, 1 reply; 3+ messages in thread
From: Adrian Hunter @ 2021-06-11  9:56 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: Ulf Hansson, linux-mmc, linux-kernel

On 11/06/21 12:03 pm, Takashi Iwai wrote:
> When DMA-mapping of the bounce buffer fails, the driver tries to fall
> back, but it leaves the allocated host->bounce_buffer although its
> size is zero.  Later on, the driver checks the use of bounce buffer
> with host->bounce_buffer pointer, and it tries to use the buffer
> incorrectly, resulting in Oops.
> 
> This patch clears the release the unused buffer and clears the
> bounce_buffer pointer for addressing the problem.
> 
> Signed-off-by: Takashi Iwai <tiwai@suse.de>

One minor comment below, otherwise:

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  drivers/mmc/host/sdhci.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
> index bf238ade1602..5f467b98ca88 100644
> --- a/drivers/mmc/host/sdhci.c
> +++ b/drivers/mmc/host/sdhci.c
> @@ -4072,9 +4072,13 @@ static void sdhci_allocate_bounce_buffer(struct sdhci_host *host)
>  					   bounce_size,
>  					   DMA_BIDIRECTIONAL);
>  	ret = dma_mapping_error(mmc_dev(mmc), host->bounce_addr);
> -	if (ret)
> +	if (ret) {
> +		devm_kfree(mmc->parent, host->bounce_buffer);

Everywhere else in this function mmc_dev(mmc) is used, so maybe
use it here too instead of mmc->parent.

> +		host->bounce_buffer = NULL;
>  		/* Again fall back to max_segs == 1 */
>  		return;
> +	}
> +
>  	host->bounce_buffer_size = bounce_size;
>  
>  	/* Lie about this since we're bouncing */
> 


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

* Re: [PATCH] mmc: sdhci: Clear unused bounce buffer at DMA mmap error path
  2021-06-11  9:56 ` Adrian Hunter
@ 2021-06-11 10:06   ` Takashi Iwai
  0 siblings, 0 replies; 3+ messages in thread
From: Takashi Iwai @ 2021-06-11 10:06 UTC (permalink / raw)
  To: Adrian Hunter; +Cc: Ulf Hansson, linux-mmc, linux-kernel

On Fri, 11 Jun 2021 11:56:16 +0200,
Adrian Hunter wrote:
> 
> On 11/06/21 12:03 pm, Takashi Iwai wrote:
> > When DMA-mapping of the bounce buffer fails, the driver tries to fall
> > back, but it leaves the allocated host->bounce_buffer although its
> > size is zero.  Later on, the driver checks the use of bounce buffer
> > with host->bounce_buffer pointer, and it tries to use the buffer
> > incorrectly, resulting in Oops.
> > 
> > This patch clears the release the unused buffer and clears the
> > bounce_buffer pointer for addressing the problem.
> > 
> > Signed-off-by: Takashi Iwai <tiwai@suse.de>
> 
> One minor comment below, otherwise:
> 
> Acked-by: Adrian Hunter <adrian.hunter@intel.com>
> 
> > ---
> >  drivers/mmc/host/sdhci.c | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
> > index bf238ade1602..5f467b98ca88 100644
> > --- a/drivers/mmc/host/sdhci.c
> > +++ b/drivers/mmc/host/sdhci.c
> > @@ -4072,9 +4072,13 @@ static void sdhci_allocate_bounce_buffer(struct sdhci_host *host)
> >  					   bounce_size,
> >  					   DMA_BIDIRECTIONAL);
> >  	ret = dma_mapping_error(mmc_dev(mmc), host->bounce_addr);
> > -	if (ret)
> > +	if (ret) {
> > +		devm_kfree(mmc->parent, host->bounce_buffer);
> 
> Everywhere else in this function mmc_dev(mmc) is used, so maybe
> use it here too instead of mmc->parent.

Doh, right, I wrote a patch based on the older kernel and refreshed
afterwards, but I forgot correcting this place.  Will resubmit the
fixed version.


thanks,

Takashi

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

end of thread, other threads:[~2021-06-11 10:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-11  9:03 [PATCH] mmc: sdhci: Clear unused bounce buffer at DMA mmap error path Takashi Iwai
2021-06-11  9:56 ` Adrian Hunter
2021-06-11 10:06   ` Takashi Iwai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.