Skip to content

Commit 498e47c

Browse files
committed
Fix build errors due to new UIO_MEM_DMA_COHERENT mess
Commit 576882e ("uio: introduce UIO_MEM_DMA_COHERENT type") introduced a new use-case for 'struct uio_mem' where the 'mem' field now contains a kernel virtual address when 'memtype' is set to UIO_MEM_DMA_COHERENT. That in turn causes build errors, because 'mem' is of type 'phys_addr_t', and a virtual address is a pointer type. When the code just blindly uses cast to mix the two, it caused problems when phys_addr_t isn't the same size as a pointer - notably on 32-bit architectures with PHYS_ADDR_T_64BIT. The proper thing to do would probably be to use a union member, and not have any casts, and make the 'mem' member be a union of 'mem.physaddr' and 'mem.vaddr', based on 'memtype'. This is not that proper thing. This is just fixing the ugly casts to be even uglier, but at least not cause build errors on 32-bit platforms with 64-bit physical addresses. Reported-by: Guenter Roeck <[email protected]> Fixes: 576882e ("uio: introduce UIO_MEM_DMA_COHERENT type") Fixes: 7722151 ("uio_pruss: UIO_MEM_DMA_COHERENT conversion") Fixes: 0199478 ("uio_dmem_genirq: UIO_MEM_DMA_COHERENT conversion") Cc: Greg Kroah-Hartman <[email protected]> Cc: Chris Leech <[email protected]> Cc: Nilesh Javali <[email protected]> Cc: Christoph Hellwig <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 5b4cdd9 commit 498e47c

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

drivers/uio/uio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ static int uio_mmap_dma_coherent(struct vm_area_struct *vma)
792792
*/
793793
vma->vm_pgoff = 0;
794794

795-
addr = (void *)mem->addr;
795+
addr = (void *)(uintptr_t)mem->addr;
796796
ret = dma_mmap_coherent(mem->dma_device,
797797
vma,
798798
addr,

drivers/uio/uio_dmem_genirq.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static int uio_dmem_genirq_open(struct uio_info *info, struct inode *inode)
6060

6161
addr = dma_alloc_coherent(&priv->pdev->dev, uiomem->size,
6262
&uiomem->dma_addr, GFP_KERNEL);
63-
uiomem->addr = addr ? (phys_addr_t) addr : DMEM_MAP_ERROR;
63+
uiomem->addr = addr ? (uintptr_t) addr : DMEM_MAP_ERROR;
6464
++uiomem;
6565
}
6666
priv->refcnt++;
@@ -89,7 +89,7 @@ static int uio_dmem_genirq_release(struct uio_info *info, struct inode *inode)
8989
break;
9090
if (uiomem->addr) {
9191
dma_free_coherent(uiomem->dma_device, uiomem->size,
92-
(void *) uiomem->addr,
92+
(void *) (uintptr_t) uiomem->addr,
9393
uiomem->dma_addr);
9494
}
9595
uiomem->addr = DMEM_MAP_ERROR;

drivers/uio/uio_pruss.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ static int pruss_probe(struct platform_device *pdev)
191191
p->mem[1].size = sram_pool_sz;
192192
p->mem[1].memtype = UIO_MEM_PHYS;
193193

194-
p->mem[2].addr = (phys_addr_t) gdev->ddr_vaddr;
194+
p->mem[2].addr = (uintptr_t) gdev->ddr_vaddr;
195195
p->mem[2].dma_addr = gdev->ddr_paddr;
196196
p->mem[2].size = extram_pool_sz;
197197
p->mem[2].memtype = UIO_MEM_DMA_COHERENT;

0 commit comments

Comments
 (0)