All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wu Fengguang <fengguang.wu@intel.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Andi Kleen <ak@linux.intel.com>, Avi Kivity <avi@qumranet.com>,
	Greg Kroah-Hartman <gregkh@suse.de>,
	Johannes Berg <johannes@sipsolutions.net>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	Mark Brown <broonie@opensource.wolfsonmicro.com>,
	Wu Fengguang <fengguang.wu@intel.com>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH 2/3] devmem: remove the "written" variable in write_kmem()
Date: Sat, 12 Sep 2009 23:20:41 +0800	[thread overview]
Message-ID: <20090912152259.257329119@intel.com> (raw)
In-Reply-To: 20090912152039.479536123@intel.com

[-- Attachment #1: kmem-remove-written.patch --]
[-- Type: text/plain, Size: 2717 bytes --]

Also rename "len" to "sz". No behavior change.

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: Wu Fengguang <fengguang.wu@intel.com>
---
 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);
 	}

-- 


  parent reply	other threads:[~2009-09-12 15:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-12 15:20 [PATCH 0/3] more /dev/[k]mem cleanups Wu Fengguang
2009-09-12 15:20 ` [PATCH 1/3] devmem: make size_inside_page() logic straight Wu Fengguang
2009-09-12 15:20 ` Wu Fengguang [this message]
2009-09-12 15:20 ` [PATCH 3/3] devmem: remove redundant parameter from do_write_kmem() Wu Fengguang
2009-09-12 15:30   ` Daniel Walker
2009-09-12 15:36     ` Wu Fengguang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090912152259.257329119@intel.com \
    --to=fengguang.wu@intel.com \
    --cc=ak@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=avi@qumranet.com \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=gregkh@suse.de \
    --cc=johannes@sipsolutions.net \
    --cc=mtosatti@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.