Skip to content

Commit b1da46d

Browse files
author
Christoph Hellwig
committed
dma-direct: simplify the use atomic pool logic in dma_direct_alloc
The logic in dma_direct_alloc when to use the atomic pool vs remapping grew a bit unreadable. Consolidate it into a single check, and clean up the set_uncached vs remap logic a bit as well. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Robin Murphy <robin.murphy@arm.com> Reviewed-by: Greg Ungerer <gerg@linux-m68k.org> Tested-by: Greg Ungerer <gerg@linux-m68k.org>
1 parent 2c8ed1b commit b1da46d

1 file changed

Lines changed: 10 additions & 15 deletions

File tree

kernel/dma/direct.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -234,27 +234,22 @@ void *dma_direct_alloc(struct device *dev, size_t size,
234234
dma_handle);
235235

236236
/*
237-
* Otherwise remap if the architecture is asking for it. But
238-
* given that remapping memory is a blocking operation we'll
239-
* instead have to dip into the atomic pools.
237+
* Otherwise we require the architecture to either be able to
238+
* mark arbitrary parts of the kernel direct mapping uncached,
239+
* or remapped it uncached.
240240
*/
241+
set_uncached = IS_ENABLED(CONFIG_ARCH_HAS_DMA_SET_UNCACHED);
241242
remap = IS_ENABLED(CONFIG_DMA_DIRECT_REMAP);
242-
if (remap) {
243-
if (dma_direct_use_pool(dev, gfp))
244-
return dma_direct_alloc_from_pool(dev, size,
245-
dma_handle, gfp);
246-
} else {
247-
if (!IS_ENABLED(CONFIG_ARCH_HAS_DMA_SET_UNCACHED))
248-
return NULL;
249-
set_uncached = true;
250-
}
243+
if (!set_uncached && !remap)
244+
return NULL;
251245
}
252246

253247
/*
254-
* Decrypting memory may block, so allocate the memory from the atomic
255-
* pools if we can't block.
248+
* Remapping or decrypting memory may block, allocate the memory from
249+
* the atomic pools instead if we aren't allowed block.
256250
*/
257-
if (force_dma_unencrypted(dev) && dma_direct_use_pool(dev, gfp))
251+
if ((remap || force_dma_unencrypted(dev)) &&
252+
dma_direct_use_pool(dev, gfp))
258253
return dma_direct_alloc_from_pool(dev, size, dma_handle, gfp);
259254

260255
/* we always manually zero the memory once we are done */

0 commit comments

Comments
 (0)