diff mbox

mmc: wbsd: safer check if dma_addr is valid DMA address

Message ID 1484347971-30829-1-git-send-email-khoroshilov@ispras.ru
State New
Headers show

Commit Message

Alexey Khoroshilov Jan. 13, 2017, 10:52 p.m. UTC
host->dma_addr can store a value that is not returned by the DMA API,
so it is safer to check if is a valid DMA address indirectly.

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
---
 drivers/mmc/host/wbsd.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Ulf Hansson Jan. 19, 2017, 11:23 a.m. UTC | #1
On 13 January 2017 at 23:52, Alexey Khoroshilov <khoroshilov@ispras.ru> wrote:
> host->dma_addr can store a value that is not returned by the DMA API,
> so it is safer to check if is a valid DMA address indirectly.
>
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>

Thanks, applied for next!

Kind regards
Uffe

> ---
>  drivers/mmc/host/wbsd.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mmc/host/wbsd.c b/drivers/mmc/host/wbsd.c
> index 80a3b11f3217..bd04e8bae010 100644
> --- a/drivers/mmc/host/wbsd.c
> +++ b/drivers/mmc/host/wbsd.c
> @@ -1437,11 +1437,14 @@ static void wbsd_request_dma(struct wbsd_host *host, int dma)
>
>  static void wbsd_release_dma(struct wbsd_host *host)
>  {
> -       if (!dma_mapping_error(mmc_dev(host->mmc), host->dma_addr)) {
> +       /*
> +        * host->dma_addr is valid here iff host->dma_buffer is not NULL.
> +        */
> +       if (host->dma_buffer) {
>                 dma_unmap_single(mmc_dev(host->mmc), host->dma_addr,
>                         WBSD_DMA_SIZE, DMA_BIDIRECTIONAL);
> +               kfree(host->dma_buffer);
>         }
> -       kfree(host->dma_buffer);
>         if (host->dma >= 0)
>                 free_dma(host->dma);
>
> --
> 2.7.4
>
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/mmc/host/wbsd.c b/drivers/mmc/host/wbsd.c
index 80a3b11f3217..bd04e8bae010 100644
--- a/drivers/mmc/host/wbsd.c
+++ b/drivers/mmc/host/wbsd.c
@@ -1437,11 +1437,14 @@  static void wbsd_request_dma(struct wbsd_host *host, int dma)
 
 static void wbsd_release_dma(struct wbsd_host *host)
 {
-	if (!dma_mapping_error(mmc_dev(host->mmc), host->dma_addr)) {
+	/*
+	 * host->dma_addr is valid here iff host->dma_buffer is not NULL.
+	 */
+	if (host->dma_buffer) {
 		dma_unmap_single(mmc_dev(host->mmc), host->dma_addr,
 			WBSD_DMA_SIZE, DMA_BIDIRECTIONAL);
+		kfree(host->dma_buffer);
 	}
-	kfree(host->dma_buffer);
 	if (host->dma >= 0)
 		free_dma(host->dma);