[PATCH 1/3] devmem: make size_inside_page() logic straight

From: Wu Fengguang
Date: Sat Sep 12 2009 - 11:25:37 EST


Also convert more size_inside_page() users.

Cc: Andi Kleen <ak@xxxxxxxxxxxxxxx>
Cc: Avi Kivity <avi@xxxxxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxx>
Cc: Johannes Berg <johannes@xxxxxxxxxxxxxxxx>
Cc: Marcelo Tosatti <mtosatti@xxxxxxxxxx>
Cc: Mark Brown <broonie@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Wu Fengguang <fengguang.wu@xxxxxxxxx>
---
drivers/char/mem.c | 34 ++++++++++++----------------------
1 file changed, 12 insertions(+), 22 deletions(-)

--- linux-mm.orig/drivers/char/mem.c 2009-09-12 23:01:24.000000000 +0800
+++ linux-mm/drivers/char/mem.c 2009-09-12 23:01:25.000000000 +0800
@@ -40,12 +40,9 @@ static inline unsigned long size_inside_
{
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);
}

/*
@@ -137,9 +134,7 @@ static ssize_t read_mem(struct file * fi
#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;
@@ -202,9 +197,7 @@ static ssize_t write_mem(struct file * f
#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;
@@ -416,15 +409,14 @@ static ssize_t read_kmem(struct file *fi
#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) {
@@ -484,9 +476,7 @@ do_write_kmem(void *p, unsigned long rea
#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;

--

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/