Skip to content

Commit 94d4b47

Browse files
author
Ingo Molnar
committed
x86/mm: Clean up types in xlate_dev_mem_ptr()
Pavel Machek reported the following compiler warning on x86/32 CONFIG_HIGHMEM64G=y builds: arch/x86/mm/ioremap.c:344:10: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] Clean up the types in this function by using a single natural type for internal calculations (unsigned long), to make it more apparent what's happening, and also to remove fragile casts. Reported-by: Pavel Machek <pavel@ucw.cz> Cc: jgross@suse.com Cc: roland@purestorage.com Link: http://lkml.kernel.org/r/20150416080440.GA507@amd Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent a6dfa12 commit 94d4b47

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

arch/x86/mm/ioremap.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,18 +332,20 @@ EXPORT_SYMBOL(iounmap);
332332
*/
333333
void *xlate_dev_mem_ptr(phys_addr_t phys)
334334
{
335-
void *addr;
336-
unsigned long start = phys & PAGE_MASK;
335+
unsigned long start = phys & PAGE_MASK;
336+
unsigned long offset = phys & ~PAGE_MASK;
337+
unsigned long vaddr;
337338

338339
/* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
339340
if (page_is_ram(start >> PAGE_SHIFT))
340341
return __va(phys);
341342

342-
addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
343-
if (addr)
344-
addr = (void *)((unsigned long)addr | (phys & ~PAGE_MASK));
343+
vaddr = (unsigned long)ioremap_cache(start, PAGE_SIZE);
344+
/* Only add the offset on success and return NULL if the ioremap() failed: */
345+
if (vaddr)
346+
vaddr += offset;
345347

346-
return addr;
348+
return (void *)vaddr;
347349
}
348350

349351
void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr)

0 commit comments

Comments
 (0)