linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mmc: wbsd: safer check if dma_addr is valid DMA address
@ 2017-01-13 22:52 Alexey Khoroshilov
  2017-01-19 11:23 ` Ulf Hansson
  0 siblings, 1 reply; 2+ messages in thread
From: Alexey Khoroshilov @ 2017-01-13 22:52 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Alexey Khoroshilov, Pierre Ossman, linux-mmc, linux-kernel, ldv-project

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(-)

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

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

* Re: [PATCH] mmc: wbsd: safer check if dma_addr is valid DMA address
  2017-01-13 22:52 [PATCH] mmc: wbsd: safer check if dma_addr is valid DMA address Alexey Khoroshilov
@ 2017-01-19 11:23 ` Ulf Hansson
  0 siblings, 0 replies; 2+ messages in thread
From: Ulf Hansson @ 2017-01-19 11:23 UTC (permalink / raw)
  To: Alexey Khoroshilov; +Cc: Pierre Ossman, linux-mmc, linux-kernel, ldv-project

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
>

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

end of thread, other threads:[~2017-01-19 11:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-13 22:52 [PATCH] mmc: wbsd: safer check if dma_addr is valid DMA address Alexey Khoroshilov
2017-01-19 11:23 ` Ulf Hansson

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).