[PATCH 1/4] MIPS: dma: fix nullptr handling in dma_free_coherent

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It is not an error to pass a null pointer to free() and as such it seems
that dma_free_coherent() should be able to handle this situation too.
Currently, if CONFIG_MMU option is enabled, we would convert this null
pointer into a pointer to the beginning of CKSEG0 memory segment before
passing it to free(), actually trying to deallocate stuff.

Signed-off-by: Denis Orlov <denorl2009@xxxxxxxxx>
---
 arch/mips/include/asm/dma-mapping.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/include/asm/dma-mapping.h b/arch/mips/include/asm/dma-mapping.h
index 8e6ea08168..9f6ec03e3b 100644
--- a/arch/mips/include/asm/dma-mapping.h
+++ b/arch/mips/include/asm/dma-mapping.h
@@ -31,7 +31,7 @@ static inline void *dma_alloc_coherent(size_t size, dma_addr_t *dma_handle)
 static inline void dma_free_coherent(void *vaddr, dma_addr_t dma_handle,
 				     size_t size)
 {
-	if (IS_ENABLED(CONFIG_MMU))
+	if (IS_ENABLED(CONFIG_MMU) && vaddr)
 		free((void *)CKSEG0ADDR(vaddr));
 	else
 		free(vaddr);
-- 
2.30.2





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux