From: Shawn Lin Date: Fri, 24 Jun 2016 09:48:57 +0000 (+0800) Subject: mmc: dw_mmc: fix unmap sg twice when finding data err X-Git-Tag: firefly_0821_release~2377 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=firefly-linux-kernel-4.4.55.git;a=commitdiff_plain;h=87a54369b8422410864794af528523024580efe9 mmc: dw_mmc: fix unmap sg twice when finding data err DATA_OVER(the same for RI/TI of IDMAC) interrupt may come up together with data error interrupts. If so, the interrupt routine set EVENT_DATA_ERR to the pending_events and schedule the tasklet but we may still fallback to the IDMAC interrupt case as the tasklet may come up a little late, namely right after the IDMAC interrupt checking. This will casue dw_mmc unmap sg twice. We can easily see it with CONFIG_DMA_API_DEBUG enabled. WARNING: CPU: 0 PID: 0 at lib/dma-debug.c:1096 check_unmap+0x7bc/0xb38 dwmmc_exynos 12200000.mmc: DMA-API: device driver tries to free DMA memory it has not allocated [device address=0x000000006d9d2200] [size=128 bytes] Modules linked in: CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.7.0-rc4 #26 Hardware name: SAMSUNG EXYNOS (Flattened Device Tree) [] (unwind_backtrace) from [] (show_stack+0x20/0x24) [] (show_stack) from [] (dump_stack+0x80/0x94) [] (dump_stack) from [] (__warn+0xf8/0x110) [] (__warn) from [] (warn_slowpath_fmt+0x48/0x50) [] (warn_slowpath_fmt) from [] (check_unmap+0x7bc/0xb38) [] (check_unmap) from [] (debug_dma_unmap_sg+0x118/0x148) [] (debug_dma_unmap_sg) from [] (dw_mci_dma_cleanup+0x7c/0xb8) [] (dw_mci_dma_cleanup) from [] (dw_mci_stop_dma+0x40/0x50) [] (dw_mci_stop_dma) from [] (dw_mci_tasklet_func+0x130/0x3b4) [] (dw_mci_tasklet_func) from [] (tasklet_action+0xb4/0x150) [] (tasklet_action) from [] (__do_softirq+0xe4/0x3cc) [] (__do_softirq) from [] (irq_exit+0xd0/0x10c) [] (irq_exit) from [] (__handle_domain_irq+0x90/0xfc) [] (__handle_domain_irq) from [] (gic_handle_irq+0x64/0xa8) [] (gic_handle_irq) from [] (__irq_svc+0x54/0x90) Exception stack(0xc1101ef8 to 0xc1101f40) 1ee0: 00000001 00000000 1f00: 00000000 c011b600 c1100000 c110753c 00000000 c11c3984 c11074d4 c1107548 1f20: 00000000 c1101f54 c1101f58 c1101f48 c010a1fc c010a200 60000013 ffffffff [] (__irq_svc) from [] (arch_cpu_idle+0x48/0x4c) [] (arch_cpu_idle) from [] (default_idle_call+0x30/0x3c) [] (default_idle_call) from [] (cpu_startup_entry+0x358/0x3b4) [] (cpu_startup_entry) from [] (rest_init+0x94/0x98) [] (rest_init) from [] (start_kernel+0x3a4/0x3b0) [] (start_kernel) from [<4000807c>] (0x4000807c) ---[ end trace 256f83eed365daf0 ]--- Change-Id: Idc1b46aeac92d715e368533352b2bb75d65d4bbd Reported-by: Seung-Woo Kim Signed-off-by: Shawn Lin --- diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index 4f0543c04528..702b088164f2 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -2489,7 +2489,8 @@ static irqreturn_t dw_mci_interrupt(int irq, void *dev_id) mci_writel(host, IDSTS64, SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI); mci_writel(host, IDSTS64, SDMMC_IDMAC_INT_NI); - host->dma_ops->complete((void *)host); + if (!test_bit(EVENT_DATA_ERROR, &host->pending_events)) + host->dma_ops->complete((void *)host); } } else { pending = mci_readl(host, IDSTS); @@ -2497,7 +2498,8 @@ static irqreturn_t dw_mci_interrupt(int irq, void *dev_id) mci_writel(host, IDSTS, SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI); mci_writel(host, IDSTS, SDMMC_IDMAC_INT_NI); - host->dma_ops->complete((void *)host); + if (!test_bit(EVENT_DATA_ERROR, &host->pending_events)) + host->dma_ops->complete((void *)host); } }