summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorWu Fengguang <fengguang.wu@intel.com>2009-12-14 17:58:09 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2009-12-15 08:53:11 -0800
commit7fabaddd09ab32a7c0c08da80315758a2245189d (patch)
treedf9d903be524ce4616344887f074ed69c8200b58 /drivers
parentfa29e97bb8c70fd7f564acbed3422403cee10ab7 (diff)
downloadlinux-7fabaddd09ab32a7c0c08da80315758a2245189d.tar.gz
linux-7fabaddd09ab32a7c0c08da80315758a2245189d.tar.bz2
linux-7fabaddd09ab32a7c0c08da80315758a2245189d.zip
/dev/mem: make size_inside_page() logic straight
Also convert more size_inside_page() users. Signed-off-by: Wu Fengguang <fengguang.wu@intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Avi Kivity <avi@qumranet.com> Cc: Greg Kroah-Hartman <gregkh@suse.de> Cc: Johannes Berg <johannes@sipsolutions.net> Cc: Marcelo Tosatti <mtosatti@redhat.com> Cc: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers')
-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,
{
unsigned long sz;
- if (-start & (PAGE_SIZE - 1))
- sz = -start & (PAGE_SIZE - 1);
- else
- sz = PAGE_SIZE;
+ sz = PAGE_SIZE - (start & (PAGE_SIZE - 1));
- return min_t(unsigned long, sz, size);
+ return min(sz, size);
}
/*
@@ -139,9 +136,7 @@ static ssize_t read_mem(struct file * file, char __user * buf,
#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED
/* we don't have page 0 mapped on sparc and m68k.. */
if (p < PAGE_SIZE) {
- sz = PAGE_SIZE - p;
- if (sz > count)
- sz = count;
+ sz = size_inside_page(p, count);
if (sz > 0) {
if (clear_user(buf, sz))
return -EFAULT;
@@ -201,9 +196,7 @@ static ssize_t write_mem(struct file * file, const char __user * buf,
#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED
/* we don't have page 0 mapped on sparc and m68k.. */
if (p < PAGE_SIZE) {
- unsigned long sz = PAGE_SIZE - p;
- if (sz > count)
- sz = count;
+ sz = size_inside_page(p, count);
/* Hmm. Do something? */
buf += sz;
p += sz;
@@ -412,15 +405,14 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED
/* we don't have page 0 mapped on sparc and m68k.. */
if (p < PAGE_SIZE && low_count > 0) {
- size_t tmp = PAGE_SIZE - p;
- if (tmp > low_count) tmp = low_count;
- if (clear_user(buf, tmp))
+ sz = size_inside_page(p, low_count);
+ if (clear_user(buf, sz))
return -EFAULT;
- buf += tmp;
- p += tmp;
- read += tmp;
- low_count -= tmp;
- count -= tmp;
+ buf += sz;
+ p += sz;
+ read += sz;
+ low_count -= sz;
+ count -= sz;
}
#endif
while (low_count > 0) {
@@ -480,9 +472,7 @@ do_write_kmem(void *p, unsigned long realp, const char __user * buf,
#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED
/* we don't have page 0 mapped on sparc and m68k.. */
if (realp < PAGE_SIZE) {
- unsigned long sz = PAGE_SIZE - realp;
- if (sz > count)
- sz = count;
+ sz = size_inside_page(realp, count);
/* Hmm. Do something? */
buf += sz;
p += sz;