mmc: renesas_sdhi: fix kernel panic in _internal_dmac.c
authorYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Fri, 20 Oct 2017 03:12:42 +0000 (12:12 +0900)
committerUlf Hansson <ulf.hansson@linaro.org>
Fri, 20 Oct 2017 09:24:58 +0000 (11:24 +0200)
Since this driver checks if the return value of dma_map_sg() is minus
or not and keeps to enable the DMAC, it may cause kernel panic when
the dma_map_sg() returns 0. So, this patch fixes the issue.

Reported-by: Dirk Behme <dirk.behme@de.bosch.com>
Fixes: 2a68ea7896e3 ("mmc: renesas-sdhi: add support for R-Car Gen3 SDHI DMAC")
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
drivers/mmc/host/renesas_sdhi_internal_dmac.c

index f905f2361d12fa5ee1757b38ddb46eb4e653066b..8bae88a150fd45b3284b594d2d090d4f78fe1fc7 100644 (file)
@@ -146,11 +146,8 @@ renesas_sdhi_internal_dmac_start_dma(struct tmio_mmc_host *host,
        WARN_ON(host->sg_len > 1);
 
        /* This DMAC cannot handle if buffer is not 8-bytes alignment */
-       if (!IS_ALIGNED(sg->offset, 8)) {
-               host->force_pio = true;
-               renesas_sdhi_internal_dmac_enable_dma(host, false);
-               return;
-       }
+       if (!IS_ALIGNED(sg->offset, 8))
+               goto force_pio;
 
        if (data->flags & MMC_DATA_READ) {
                dtran_mode |= DTRAN_MODE_CH_NUM_CH1;
@@ -163,8 +160,8 @@ renesas_sdhi_internal_dmac_start_dma(struct tmio_mmc_host *host,
        }
 
        ret = dma_map_sg(&host->pdev->dev, sg, host->sg_len, dir);
-       if (ret < 0)
-               return;
+       if (ret == 0)
+               goto force_pio;
 
        renesas_sdhi_internal_dmac_enable_dma(host, true);
 
@@ -176,6 +173,12 @@ renesas_sdhi_internal_dmac_start_dma(struct tmio_mmc_host *host,
                                            dtran_mode);
        renesas_sdhi_internal_dmac_dm_write(host, DM_DTRAN_ADDR,
                                            sg->dma_address);
+
+       return;
+
+force_pio:
+       host->force_pio = true;
+       renesas_sdhi_internal_dmac_enable_dma(host, false);
 }
 
 static void renesas_sdhi_internal_dmac_issue_tasklet_fn(unsigned long arg)