Skip to content

Commit 4a54d16

Browse files
author
Christoph Hellwig
committed
dma-mapping: truncate dma masks to what dma_addr_t can hold
The dma masks in struct device are always 64-bits wide. But for builds using a 32-bit dma_addr_t we need to ensure we don't store an unsupportable value. Before Linux 5.0 this was handled at least by the ARM dma mapping code by never allowing to set a larger dma_mask, but these days we allow the driver to just set the largest supported value and never fall back to a smaller one. Ensure this always works by truncating the value. Fixes: 9eb9e96 ("Documentation/DMA-API-HOWTO: update dma_mask sections") Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent 591fcf3 commit 4a54d16

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎kernel/dma/mapping.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,12 @@ void arch_dma_set_mask(struct device *dev, u64 mask);
317317

318318
int dma_set_mask(struct device *dev, u64 mask)
319319
{
320+
/*
321+
* Truncate the mask to the actually supported dma_addr_t width to
322+
* avoid generating unsupportable addresses.
323+
*/
324+
mask = (dma_addr_t)mask;
325+
320326
if (!dev->dma_mask || !dma_supported(dev, mask))
321327
return -EIO;
322328

@@ -330,6 +336,12 @@ EXPORT_SYMBOL(dma_set_mask);
330336
#ifndef CONFIG_ARCH_HAS_DMA_SET_COHERENT_MASK
331337
int dma_set_coherent_mask(struct device *dev, u64 mask)
332338
{
339+
/*
340+
* Truncate the mask to the actually supported dma_addr_t width to
341+
* avoid generating unsupportable addresses.
342+
*/
343+
mask = (dma_addr_t)mask;
344+
333345
if (!dma_supported(dev, mask))
334346
return -EIO;
335347

0 commit comments

Comments
 (0)