aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/mem.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/mem.c')
-rw-r--r--drivers/char/mem.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 26d0116b48d4..5245ba1649ed 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -88,21 +88,15 @@ static inline int uncached_access(struct file *file, unsigned long addr)
88} 88}
89 89
90#ifndef ARCH_HAS_VALID_PHYS_ADDR_RANGE 90#ifndef ARCH_HAS_VALID_PHYS_ADDR_RANGE
91static inline int valid_phys_addr_range(unsigned long addr, size_t *count) 91static inline int valid_phys_addr_range(unsigned long addr, size_t count)
92{ 92{
93 unsigned long end_mem; 93 if (addr + count > __pa(high_memory))
94
95 end_mem = __pa(high_memory);
96 if (addr >= end_mem)
97 return 0; 94 return 0;
98 95
99 if (*count > end_mem - addr)
100 *count = end_mem - addr;
101
102 return 1; 96 return 1;
103} 97}
104 98
105static inline int valid_mmap_phys_addr_range(unsigned long addr, size_t *size) 99static inline int valid_mmap_phys_addr_range(unsigned long addr, size_t size)
106{ 100{
107 return 1; 101 return 1;
108} 102}
@@ -119,7 +113,7 @@ static ssize_t read_mem(struct file * file, char __user * buf,
119 ssize_t read, sz; 113 ssize_t read, sz;
120 char *ptr; 114 char *ptr;
121 115
122 if (!valid_phys_addr_range(p, &count)) 116 if (!valid_phys_addr_range(p, count))
123 return -EFAULT; 117 return -EFAULT;
124 read = 0; 118 read = 0;
125#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED 119#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED
@@ -177,7 +171,7 @@ static ssize_t write_mem(struct file * file, const char __user * buf,
177 unsigned long copied; 171 unsigned long copied;
178 void *ptr; 172 void *ptr;
179 173
180 if (!valid_phys_addr_range(p, &count)) 174 if (!valid_phys_addr_range(p, count))
181 return -EFAULT; 175 return -EFAULT;
182 176
183 written = 0; 177 written = 0;
@@ -249,7 +243,7 @@ static int mmap_mem(struct file * file, struct vm_area_struct * vma)
249{ 243{
250 size_t size = vma->vm_end - vma->vm_start; 244 size_t size = vma->vm_end - vma->vm_start;
251 245
252 if (!valid_mmap_phys_addr_range(vma->vm_pgoff << PAGE_SHIFT, &size)) 246 if (!valid_mmap_phys_addr_range(vma->vm_pgoff << PAGE_SHIFT, size))
253 return -EINVAL; 247 return -EINVAL;
254 248
255 vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff, 249 vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff,