aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/mem.c34
1 files changed, 12 insertions, 22 deletions
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index c6b2fbc5ed47..192af59afc13 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -39,12 +39,9 @@ static inline unsigned long size_inside_page(unsigned long start,
39{ 39{
40 unsigned long sz; 40 unsigned long sz;
41 41
42 if (-start & (PAGE_SIZE - 1)) 42 sz = PAGE_SIZE - (start & (PAGE_SIZE - 1));
43 sz = -start & (PAGE_SIZE - 1);
44 else
45 sz = PAGE_SIZE;
46 43
47 return min_t(unsigned long, sz, size); 44 return min(sz, size);
48} 45}
49 46
50/* 47/*
@@ -139,9 +136,7 @@ static ssize_t read_mem(struct file * file, char __user * buf,
139#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED 136#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED
140 /* we don't have page 0 mapped on sparc and m68k.. */ 137 /* we don't have page 0 mapped on sparc and m68k.. */
141 if (p < PAGE_SIZE) { 138 if (p < PAGE_SIZE) {
142 sz = PAGE_SIZE - p; 139 sz = size_inside_page(p, count);
143 if (sz > count)
144 sz = count;
145 if (sz > 0) { 140 if (sz > 0) {
146 if (clear_user(buf, sz)) 141 if (clear_user(buf, sz))
147 return -EFAULT; 142 return -EFAULT;
@@ -201,9 +196,7 @@ static ssize_t write_mem(struct file * file, const char __user * buf,
201#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED 196#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED
202 /* we don't have page 0 mapped on sparc and m68k.. */ 197 /* we don't have page 0 mapped on sparc and m68k.. */
203 if (p < PAGE_SIZE) { 198 if (p < PAGE_SIZE) {
204 unsigned long sz = PAGE_SIZE - p; 199 sz = size_inside_page(p, count);
205 if (sz > count)
206 sz = count;
207 /* Hmm. Do something? */ 200 /* Hmm. Do something? */
208 buf += sz; 201 buf += sz;
209 p += sz; 202 p += sz;
@@ -412,15 +405,14 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
412#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED 405#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED
413 /* we don't have page 0 mapped on sparc and m68k.. */ 406 /* we don't have page 0 mapped on sparc and m68k.. */
414 if (p < PAGE_SIZE && low_count > 0) { 407 if (p < PAGE_SIZE && low_count > 0) {
415 size_t tmp = PAGE_SIZE - p; 408 sz = size_inside_page(p, low_count);
416 if (tmp > low_count) tmp = low_count; 409 if (clear_user(buf, sz))
417 if (clear_user(buf, tmp))
418 return -EFAULT; 410 return -EFAULT;
419 buf += tmp; 411 buf += sz;
420 p += tmp; 412 p += sz;
421 read += tmp; 413 read += sz;
422 low_count -= tmp; 414 low_count -= sz;
423 count -= tmp; 415 count -= sz;
424 } 416 }
425#endif 417#endif
426 while (low_count > 0) { 418 while (low_count > 0) {
@@ -480,9 +472,7 @@ do_write_kmem(void *p, unsigned long realp, const char __user * buf,
480#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED 472#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED
481 /* we don't have page 0 mapped on sparc and m68k.. */ 473 /* we don't have page 0 mapped on sparc and m68k.. */
482 if (realp < PAGE_SIZE) { 474 if (realp < PAGE_SIZE) {
483 unsigned long sz = PAGE_SIZE - realp; 475 sz = size_inside_page(realp, count);
484 if (sz > count)
485 sz = count;
486 /* Hmm. Do something? */ 476 /* Hmm. Do something? */
487 buf += sz; 477 buf += sz;
488 p += sz; 478 p += sz;