History

dma-mapping: avoid oops when parameter cpu_addr is null

To keep consistent with kfree, which tolerate ptr is NULL. We do this because sometimes we may use goto statement, so that success and failure case can share parts of the code. But unfortunately, dma_free_coherent called with parameter cpu_addr is null will cause oops, such as showed below: Unable to handle kernel paging request at virtual address ffffffc020d3b2b8 pgd = ffffffc083a61000 [ffffffc020d3b2b8] *pgd=0000000000000000, *pud=0000000000000000 CPU: 4 PID: 1489 Comm: malloc_dma_1 Tainted: G O 4.1.12 #1 Hardware name: ARM64 (DT) PC is at __dma_free_coherent.isra.10+0x74/0xc8 LR is at __dma_free+0x9c/0xb0 Process malloc_dma_1 (pid: 1489, stack limit = 0xffffffc0837fc020) [...] Call trace: __dma_free_coherent.isra.10+0x74/0xc8 __dma_free+0x9c/0xb0 malloc_dma+0x104/0x158 [dma_alloc_coherent_mtmalloc] kthread+0xec/0xfc

Zhen Lei committed 10 years ago

Commit d6b7eae1 parent 86613621 file · +1 −1Browse files

Showing the changes to include (1 of 1 file). Show all

Unified · Split

include/linux/dma-mapping.h+1−1
@@ -386,7 +386,7 @@ static inline void dma_free_attrs(struct device *dev, size_t size, · 385 unmodified lines
386386 if (dma_release_from_coherent(dev, get_order(size), cpu_addr))
387387 return;
388388
389− if (!ops->free)
389+ if (!ops->free || !cpu_addr)
390390 return;
391391
392392 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);