Skip to content

Commit 8270f3a

Browse files
author
Christoph Hellwig
committed
dma-direct: fix DMA_ATTR_NO_KERNEL_MAPPING for remapped allocations
We need to return a dma_addr_t even if we don't have a kernel mapping. Do so by consolidating the phys_to_dma call in a single place and jump to it from all the branches that return successfully. Fixes: bfd56cd ("dma-mapping: support highmem in the generic remap allocator") Reported-by: Liviu Dudau <liviu@dudau.co.uk Signed-off-by: Christoph Hellwig <hch@lst.de> Tested-by: Liviu Dudau <liviu@dudau.co.uk>
1 parent 06f55fd commit 8270f3a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

kernel/dma/remap.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
204204
ret = dma_alloc_from_pool(size, &page, flags);
205205
if (!ret)
206206
return NULL;
207-
*dma_handle = phys_to_dma(dev, page_to_phys(page));
208-
return ret;
207+
goto done;
209208
}
210209

211210
page = __dma_direct_alloc_pages(dev, size, dma_handle, flags, attrs);
@@ -215,8 +214,10 @@ void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
215214
/* remove any dirty cache lines on the kernel alias */
216215
arch_dma_prep_coherent(page, size);
217216

218-
if (attrs & DMA_ATTR_NO_KERNEL_MAPPING)
219-
return page; /* opaque cookie */
217+
if (attrs & DMA_ATTR_NO_KERNEL_MAPPING) {
218+
ret = page; /* opaque cookie */
219+
goto done;
220+
}
220221

221222
/* create a coherent mapping */
222223
ret = dma_common_contiguous_remap(page, size, VM_USERMAP,
@@ -227,9 +228,9 @@ void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
227228
return ret;
228229
}
229230

230-
*dma_handle = phys_to_dma(dev, page_to_phys(page));
231231
memset(ret, 0, size);
232-
232+
done:
233+
*dma_handle = phys_to_dma(dev, page_to_phys(page));
233234
return ret;
234235
}
235236

0 commit comments

Comments
 (0)