public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Wu Fengguang <fengguang.wu@intel.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "mtosatti@redhat.com" <mtosatti@redhat.com>,
	"gregkh@suse.de" <gregkh@suse.de>,
	"broonie@opensource.wolfsonmicro.com" 
	<broonie@opensource.wolfsonmicro.com>,
	"johannes@sipsolutions.net" <johannes@sipsolutions.net>,
	"avi@qumranet.com" <avi@qumranet.com>,
	"andi@firstfloor.org" <andi@firstfloor.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/3] devmem: remove redundant test on len
Date: Sat, 12 Sep 2009 22:32:56 +0800	[thread overview]
Message-ID: <20090912143256.GA6511@localhost> (raw)
In-Reply-To: <20090911170047.94de0896.akpm@linux-foundation.org>

On Sat, Sep 12, 2009 at 08:00:47AM +0800, Andrew Morton wrote:
> On Fri, 11 Sep 2009 10:23:34 +0800
> Wu Fengguang <fengguang.wu@intel.com> wrote:
> 
> > The len test in write_kmem() is always true, so can be reduced.
> > 
> > CC: Marcelo Tosatti <mtosatti@redhat.com>
> > CC: Greg Kroah-Hartman <gregkh@suse.de>
> > CC: Mark Brown <broonie@opensource.wolfsonmicro.com>
> > CC: Johannes Berg <johannes@sipsolutions.net>
> > CC: Avi Kivity <avi@qumranet.com>
> > Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
> > ---
> >  drivers/char/mem.c |   14 ++++++--------
> >  1 file changed, 6 insertions(+), 8 deletions(-)
> > 
> > --- linux.orig/drivers/char/mem.c
> > +++ linux/drivers/char/mem.c
> > @@ -580,18 +580,16 @@ static ssize_t write_kmem(struct file * 
> >  		while (count > 0) {
> >  			int len = count;
> >  
> >  			if (len > PAGE_SIZE)
> >  				len = PAGE_SIZE;
> > -			if (len) {
> > -				written = copy_from_user(kbuf, buf, len);
> > -				if (written) {
> > -					if (wrote + virtr)
> > -						break;
> > -					free_page((unsigned long)kbuf);
> > -					return -EFAULT;
> > -				}
> > +			written = copy_from_user(kbuf, buf, len);
> > +			if (written) {
> > +				if (wrote + virtr)
> > +					break;
> > +				free_page((unsigned long)kbuf);
> > +				return -EFAULT;
> >  			}
> >  			len = vwrite(kbuf, (char *)p, len);
> >  			count -= len;
> >  			buf += len;
> >  			virtr += len;
> 
> humpf.  But take a closer look at what remains.

Yeah, it asks for more cleanup patches..

> 
> Local var `written' is unneeded here.
> 
> 
> Which makes us look at what `written' _does_ do:
> 
> 		if (written != wrote)
> 			return written;
> 		wrote = written;
> 
> lolwhowrotethat?
> 
> local var `written' can at least be made local to the first loop.

Right, I'll make this straight.

> write_kmem() has a lot of typecasts which indicates that the choices of
> types were inappropriate.

It seems hard to improve because of a fundamental issue: the same
value is taken as both virtual and physical address, and also be
compared and calculated as numbers..

Thanks,
Fengguang


  reply	other threads:[~2009-09-12 14:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-11  2:23 [PATCH 0/3] /dev/mem cleanups and bug fix Wu Fengguang
2009-09-11  2:23 ` [PATCH 1/3] devmem: remove redundant test on len Wu Fengguang
2009-09-12  0:00   ` Andrew Morton
2009-09-12 14:32     ` Wu Fengguang [this message]
2009-09-11  2:23 ` [PATCH 2/3] devmem: introduce size_inside_page() Wu Fengguang
2009-09-11 23:55   ` Andrew Morton
2009-09-12 14:41     ` Wu Fengguang
2009-09-11  2:23 ` [PATCH 3/3] devmem: cleanup unxlate_dev_mem_ptr() calls Wu Fengguang
2009-09-12  0:05   ` Andrew Morton
2009-09-12 14:57     ` Wu Fengguang
2009-09-11  7:44 ` [PATCH 0/3] /dev/mem cleanups and bug fix Andi Kleen

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=20090912143256.GA6511@localhost \
    --to=fengguang.wu@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=andi@firstfloor.org \
    --cc=avi@qumranet.com \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=gregkh@suse.de \
    --cc=johannes@sipsolutions.net \
    --cc=linux-kernel@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox