Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drivers: dma-coherent: simplify dma_init_coherent_memory return value

Since only dma_declare_coherent_memory cares about
dma_init_coherent_memory returning part of flags as it return value,
move the condition to the former and simplify the latter. This in
turn makes rmem_dma_device_init less confusing.

Reported-by: Fugang Duan <B38611@freescale.com>
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Michal Nazarewicz and committed by
Greg Kroah-Hartman
9e5b3d6f 92aed5d6

+11 -17
+11 -17
drivers/base/dma-coherent.c
··· 17 17 spinlock_t spinlock; 18 18 }; 19 19 20 - static int dma_init_coherent_memory(phys_addr_t phys_addr, dma_addr_t device_addr, 21 - size_t size, int flags, 22 - struct dma_coherent_mem **mem) 20 + static bool dma_init_coherent_memory( 21 + phys_addr_t phys_addr, dma_addr_t device_addr, size_t size, int flags, 22 + struct dma_coherent_mem **mem) 23 23 { 24 24 struct dma_coherent_mem *dma_mem = NULL; 25 25 void __iomem *mem_base = NULL; ··· 50 50 spin_lock_init(&dma_mem->spinlock); 51 51 52 52 *mem = dma_mem; 53 - 54 - if (flags & DMA_MEMORY_MAP) 55 - return DMA_MEMORY_MAP; 56 - 57 - return DMA_MEMORY_IO; 53 + return true; 58 54 59 55 out: 60 56 kfree(dma_mem); 61 57 if (mem_base) 62 58 iounmap(mem_base); 63 - return 0; 59 + return false; 64 60 } 65 61 66 62 static void dma_release_coherent_memory(struct dma_coherent_mem *mem) ··· 84 88 dma_addr_t device_addr, size_t size, int flags) 85 89 { 86 90 struct dma_coherent_mem *mem; 87 - int ret; 88 91 89 - ret = dma_init_coherent_memory(phys_addr, device_addr, size, flags, 90 - &mem); 91 - if (ret == 0) 92 + if (!dma_init_coherent_memory(phys_addr, device_addr, size, flags, 93 + &mem)) 92 94 return 0; 93 95 94 96 if (dma_assign_coherent_memory(dev, mem) == 0) 95 - return ret; 97 + return flags & DMA_MEMORY_MAP ? DMA_MEMORY_MAP : DMA_MEMORY_IO; 96 98 97 99 dma_release_coherent_memory(mem); 98 100 return 0; ··· 275 281 struct dma_coherent_mem *mem = rmem->priv; 276 282 277 283 if (!mem && 278 - dma_init_coherent_memory(rmem->base, rmem->base, rmem->size, 279 - DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE, 280 - &mem) != DMA_MEMORY_MAP) { 284 + !dma_init_coherent_memory(rmem->base, rmem->base, rmem->size, 285 + DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE, 286 + &mem)) { 281 287 pr_err("Reserved memory: failed to init DMA memory pool at %pa, size %ld MiB\n", 282 288 &rmem->base, (unsigned long)rmem->size / SZ_1M); 283 289 return -ENODEV;