Also rename "len" to "sz". No behavior change. Cc: Andi Kleen Cc: Avi Kivity Cc: Greg Kroah-Hartman Cc: Johannes Berg Cc: Marcelo Tosatti Cc: Mark Brown Signed-off-by: Wu Fengguang --- drivers/char/mem.c | 48 ++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) --- linux-mm.orig/drivers/char/mem.c 2009-09-12 23:03:41.000000000 +0800 +++ linux-mm/drivers/char/mem.c 2009-09-12 23:14:33.000000000 +0800 @@ -444,19 +444,18 @@ static ssize_t read_kmem(struct file *fi if (!kbuf) return -ENOMEM; while (count > 0) { - int len = size_inside_page(p, count); - - len = vread(kbuf, (char *)p, len); - if (!len) + sz = size_inside_page(p, count); + sz = vread(kbuf, (char *)p, sz); + if (!sz) break; - if (copy_to_user(buf, kbuf, len)) { + if (copy_to_user(buf, kbuf, sz)) { free_page((unsigned long)kbuf); return -EFAULT; } - count -= len; - buf += len; - read += len; - p += len; + count -= sz; + buf += sz; + read += sz; + p += sz; } free_page((unsigned long)kbuf); } @@ -526,19 +525,14 @@ static ssize_t write_kmem(struct file * unsigned long p = *ppos; ssize_t wrote = 0; ssize_t virtr = 0; - ssize_t written; char * kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */ if (p < (unsigned long) high_memory) { - - wrote = count; - if (count > (unsigned long) high_memory - p) - wrote = (unsigned long) high_memory - p; - - written = do_write_kmem((void*)p, p, buf, wrote, ppos); - if (written != wrote) - return written; - wrote = written; + unsigned long to_write = min_t(unsigned long, count, + (unsigned long)high_memory - p); + wrote = do_write_kmem((void *)p, p, buf, to_write, ppos); + if (wrote != to_write) + return wrote; p += wrote; buf += wrote; count -= wrote; @@ -549,20 +543,20 @@ static ssize_t write_kmem(struct file * if (!kbuf) return wrote ? wrote : -ENOMEM; while (count > 0) { - int len = size_inside_page(p, count); + unsigned long sz = size_inside_page(p, count); - written = copy_from_user(kbuf, buf, len); - if (written) { + sz = copy_from_user(kbuf, buf, sz); + if (sz) { if (wrote + virtr) break; free_page((unsigned long)kbuf); return -EFAULT; } - len = vwrite(kbuf, (char *)p, len); - count -= len; - buf += len; - virtr += len; - p += len; + sz = vwrite(kbuf, (char *)p, sz); + count -= sz; + buf += sz; + virtr += sz; + p += sz; } free_page((unsigned long)kbuf); } -- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/