aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Reding <treding@nvidia.com>2014-07-28 11:20:33 -0400
committerThierry Reding <treding@nvidia.com>2014-11-10 09:59:21 -0500
commit4707a341b4af57c72c1573a89d303559cf7bcf88 (patch)
treeadf5f6360dafaf60e00995326b92cf1664828662
parentdc01201476ec9d62e81c0ee181531bccd8b007ff (diff)
/dev/mem: Use more consistent data types
The xlate_dev_{kmem,mem}_ptr() functions take either a physical address or a kernel virtual address, so data types should be phys_addr_t and void *. They both return a kernel virtual address which is only ever used in calls to copy_{from,to}_user(), so make variables that store it void * rather than char * for consistency. Also only define a weak unxlate_dev_mem_ptr() function if architectures haven't overridden them in the asm/io.h header file. Signed-off-by: Thierry Reding <treding@nvidia.com>
-rw-r--r--arch/s390/include/asm/io.h5
-rw-r--r--arch/s390/mm/maccess.c4
-rw-r--r--arch/x86/include/asm/io.h4
-rw-r--r--arch/x86/mm/ioremap.c4
-rw-r--r--drivers/char/mem.c13
5 files changed, 17 insertions, 13 deletions
diff --git a/arch/s390/include/asm/io.h b/arch/s390/include/asm/io.h
index cd6b9ee7b69c..d22c2eeae78f 100644
--- a/arch/s390/include/asm/io.h
+++ b/arch/s390/include/asm/io.h
@@ -13,9 +13,10 @@
13#include <asm/page.h> 13#include <asm/page.h>
14#include <asm/pci_io.h> 14#include <asm/pci_io.h>
15 15
16void *xlate_dev_mem_ptr(unsigned long phys);
17#define xlate_dev_mem_ptr xlate_dev_mem_ptr 16#define xlate_dev_mem_ptr xlate_dev_mem_ptr
18void unxlate_dev_mem_ptr(unsigned long phys, void *addr); 17void *xlate_dev_mem_ptr(phys_addr_t phys);
18#define unxlate_dev_mem_ptr unxlate_dev_mem_ptr
19void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr);
19 20
20/* 21/*
21 * Convert a virtual cached pointer to an uncached pointer 22 * Convert a virtual cached pointer to an uncached pointer
diff --git a/arch/s390/mm/maccess.c b/arch/s390/mm/maccess.c
index 2a2e35416d2f..2eb34bdfc613 100644
--- a/arch/s390/mm/maccess.c
+++ b/arch/s390/mm/maccess.c
@@ -176,7 +176,7 @@ static int is_swapped(unsigned long addr)
176 * For swapped prefix pages a new buffer is returned that contains a copy of 176 * For swapped prefix pages a new buffer is returned that contains a copy of
177 * the absolute memory. The buffer size is maximum one page large. 177 * the absolute memory. The buffer size is maximum one page large.
178 */ 178 */
179void *xlate_dev_mem_ptr(unsigned long addr) 179void *xlate_dev_mem_ptr(phys_addr_t addr)
180{ 180{
181 void *bounce = (void *) addr; 181 void *bounce = (void *) addr;
182 unsigned long size; 182 unsigned long size;
@@ -197,7 +197,7 @@ void *xlate_dev_mem_ptr(unsigned long addr)
197/* 197/*
198 * Free converted buffer for /dev/mem access (if necessary) 198 * Free converted buffer for /dev/mem access (if necessary)
199 */ 199 */
200void unxlate_dev_mem_ptr(unsigned long addr, void *buf) 200void unxlate_dev_mem_ptr(phys_addr_t addr, void *buf)
201{ 201{
202 if ((void *) addr != buf) 202 if ((void *) addr != buf)
203 free_page((unsigned long) buf); 203 free_page((unsigned long) buf);
diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
index b8237d8a1e0c..ae2b593e7c6e 100644
--- a/arch/x86/include/asm/io.h
+++ b/arch/x86/include/asm/io.h
@@ -310,8 +310,8 @@ BUILDIO(b, b, char)
310BUILDIO(w, w, short) 310BUILDIO(w, w, short)
311BUILDIO(l, , int) 311BUILDIO(l, , int)
312 312
313extern void *xlate_dev_mem_ptr(unsigned long phys); 313extern void *xlate_dev_mem_ptr(phys_addr_t phys);
314extern void unxlate_dev_mem_ptr(unsigned long phys, void *addr); 314extern void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr);
315 315
316extern int ioremap_change_attr(unsigned long vaddr, unsigned long size, 316extern int ioremap_change_attr(unsigned long vaddr, unsigned long size,
317 unsigned long prot_val); 317 unsigned long prot_val);
diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
index af78e50ca6ce..b12f43c192cf 100644
--- a/arch/x86/mm/ioremap.c
+++ b/arch/x86/mm/ioremap.c
@@ -327,7 +327,7 @@ EXPORT_SYMBOL(iounmap);
327 * Convert a physical pointer to a virtual kernel pointer for /dev/mem 327 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
328 * access 328 * access
329 */ 329 */
330void *xlate_dev_mem_ptr(unsigned long phys) 330void *xlate_dev_mem_ptr(phys_addr_t phys)
331{ 331{
332 void *addr; 332 void *addr;
333 unsigned long start = phys & PAGE_MASK; 333 unsigned long start = phys & PAGE_MASK;
@@ -343,7 +343,7 @@ void *xlate_dev_mem_ptr(unsigned long phys)
343 return addr; 343 return addr;
344} 344}
345 345
346void unxlate_dev_mem_ptr(unsigned long phys, void *addr) 346void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr)
347{ 347{
348 if (page_is_ram(phys >> PAGE_SHIFT)) 348 if (page_is_ram(phys >> PAGE_SHIFT))
349 return; 349 return;
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 524b707894ef..4c58333b4257 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -84,9 +84,12 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
84} 84}
85#endif 85#endif
86 86
87void __weak unxlate_dev_mem_ptr(unsigned long phys, void *addr) 87#ifndef unxlate_dev_mem_ptr
88#define unxlate_dev_mem_ptr unxlate_dev_mem_ptr
89void __weak unxlate_dev_mem_ptr(phys_addr_t phys, void *addr)
88{ 90{
89} 91}
92#endif
90 93
91/* 94/*
92 * This funcion reads the *physical* memory. The f_pos points directly to the 95 * This funcion reads the *physical* memory. The f_pos points directly to the
@@ -97,7 +100,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
97{ 100{
98 phys_addr_t p = *ppos; 101 phys_addr_t p = *ppos;
99 ssize_t read, sz; 102 ssize_t read, sz;
100 char *ptr; 103 void *ptr;
101 104
102 if (p != *ppos) 105 if (p != *ppos)
103 return 0; 106 return 0;
@@ -400,7 +403,7 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
400 * uncached, then it must also be accessed uncached 403 * uncached, then it must also be accessed uncached
401 * by the kernel or data corruption may occur 404 * by the kernel or data corruption may occur
402 */ 405 */
403 kbuf = xlate_dev_kmem_ptr((char *)p); 406 kbuf = xlate_dev_kmem_ptr((void *)p);
404 407
405 if (copy_to_user(buf, kbuf, sz)) 408 if (copy_to_user(buf, kbuf, sz))
406 return -EFAULT; 409 return -EFAULT;
@@ -461,7 +464,7 @@ static ssize_t do_write_kmem(unsigned long p, const char __user *buf,
461#endif 464#endif
462 465
463 while (count > 0) { 466 while (count > 0) {
464 char *ptr; 467 void *ptr;
465 468
466 sz = size_inside_page(p, count); 469 sz = size_inside_page(p, count);
467 470
@@ -470,7 +473,7 @@ static ssize_t do_write_kmem(unsigned long p, const char __user *buf,
470 * it must also be accessed uncached by the kernel or data 473 * it must also be accessed uncached by the kernel or data
471 * corruption may occur. 474 * corruption may occur.
472 */ 475 */
473 ptr = xlate_dev_kmem_ptr((char *)p); 476 ptr = xlate_dev_kmem_ptr((void *)p);
474 477
475 copied = copy_from_user(ptr, buf, sz); 478 copied = copy_from_user(ptr, buf, sz);
476 if (copied) { 479 if (copied) {