From: Takashi Iwai <tiwai@suse.de>
Subject: [PATCH v2] mmc: sdhci: Clear unused bounce buffer at DMA mmap error path
Date: Fri, 11 Jun 2021 12:19:48 +0200
Message-Id: <20210611101948.18972-1-tiwai@suse.de>
References: bsc#1187039
Patch-mainline: v5.14-rc1
Git-commit: 49036ba889e346da6ebf2f741fe0b0ee49a11b08
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.
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
v1->v2: correct the device pointer to mmc_dev(mmc)
drivers/mmc/host/sdhci.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -3929,9 +3929,13 @@ static void sdhci_allocate_bounce_buffer
bounce_size,
DMA_BIDIRECTIONAL);
ret = dma_mapping_error(mmc->parent, 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 */