Commit 498e47cd authored by Linus Torvalds's avatar Linus Torvalds

Fix build errors due to new UIO_MEM_DMA_COHERENT mess

Commit 576882ef ("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: default avatarGuenter Roeck <linux@roeck-us.net>
Fixes: 576882ef ("uio: introduce UIO_MEM_DMA_COHERENT type")
Fixes: 7722151e ("uio_pruss: UIO_MEM_DMA_COHERENT conversion")
Fixes: 01994780 ("uio_dmem_genirq: UIO_MEM_DMA_COHERENT conversion")
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Chris Leech <cleech@redhat.com>
Cc: Nilesh Javali <njavali@marvell.com>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: default avatarLinus Torvalds <torvalds@linuxfoundation.org>
parent 5b4cdd9c
...@@ -792,7 +792,7 @@ static int uio_mmap_dma_coherent(struct vm_area_struct *vma) ...@@ -792,7 +792,7 @@ static int uio_mmap_dma_coherent(struct vm_area_struct *vma)
*/ */
vma->vm_pgoff = 0; vma->vm_pgoff = 0;
addr = (void *)mem->addr; addr = (void *)(uintptr_t)mem->addr;
ret = dma_mmap_coherent(mem->dma_device, ret = dma_mmap_coherent(mem->dma_device,
vma, vma,
addr, addr,
......
...@@ -60,7 +60,7 @@ static int uio_dmem_genirq_open(struct uio_info *info, struct inode *inode) ...@@ -60,7 +60,7 @@ static int uio_dmem_genirq_open(struct uio_info *info, struct inode *inode)
addr = dma_alloc_coherent(&priv->pdev->dev, uiomem->size, addr = dma_alloc_coherent(&priv->pdev->dev, uiomem->size,
&uiomem->dma_addr, GFP_KERNEL); &uiomem->dma_addr, GFP_KERNEL);
uiomem->addr = addr ? (phys_addr_t) addr : DMEM_MAP_ERROR; uiomem->addr = addr ? (uintptr_t) addr : DMEM_MAP_ERROR;
++uiomem; ++uiomem;
} }
priv->refcnt++; priv->refcnt++;
...@@ -89,7 +89,7 @@ static int uio_dmem_genirq_release(struct uio_info *info, struct inode *inode) ...@@ -89,7 +89,7 @@ static int uio_dmem_genirq_release(struct uio_info *info, struct inode *inode)
break; break;
if (uiomem->addr) { if (uiomem->addr) {
dma_free_coherent(uiomem->dma_device, uiomem->size, dma_free_coherent(uiomem->dma_device, uiomem->size,
(void *) uiomem->addr, (void *) (uintptr_t) uiomem->addr,
uiomem->dma_addr); uiomem->dma_addr);
} }
uiomem->addr = DMEM_MAP_ERROR; uiomem->addr = DMEM_MAP_ERROR;
......
...@@ -191,7 +191,7 @@ static int pruss_probe(struct platform_device *pdev) ...@@ -191,7 +191,7 @@ static int pruss_probe(struct platform_device *pdev)
p->mem[1].size = sram_pool_sz; p->mem[1].size = sram_pool_sz;
p->mem[1].memtype = UIO_MEM_PHYS; p->mem[1].memtype = UIO_MEM_PHYS;
p->mem[2].addr = (phys_addr_t) gdev->ddr_vaddr; p->mem[2].addr = (uintptr_t) gdev->ddr_vaddr;
p->mem[2].dma_addr = gdev->ddr_paddr; p->mem[2].dma_addr = gdev->ddr_paddr;
p->mem[2].size = extram_pool_sz; p->mem[2].size = extram_pool_sz;
p->mem[2].memtype = UIO_MEM_DMA_COHERENT; p->mem[2].memtype = UIO_MEM_DMA_COHERENT;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment