[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20090912143256.GA6511@localhost>
Date: Sat, 12 Sep 2009 22:32:56 +0800
From: Wu Fengguang <fengguang.wu@...el.com>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: "mtosatti@...hat.com" <mtosatti@...hat.com>,
"gregkh@...e.de" <gregkh@...e.de>,
"broonie@...nsource.wolfsonmicro.com"
<broonie@...nsource.wolfsonmicro.com>,
"johannes@...solutions.net" <johannes@...solutions.net>,
"avi@...ranet.com" <avi@...ranet.com>,
"andi@...stfloor.org" <andi@...stfloor.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 1/3] devmem: remove redundant test on len
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@...el.com> wrote:
>
> > The len test in write_kmem() is always true, so can be reduced.
> >
> > CC: Marcelo Tosatti <mtosatti@...hat.com>
> > CC: Greg Kroah-Hartman <gregkh@...e.de>
> > CC: Mark Brown <broonie@...nsource.wolfsonmicro.com>
> > CC: Johannes Berg <johannes@...solutions.net>
> > CC: Avi Kivity <avi@...ranet.com>
> > Signed-off-by: Wu Fengguang <fengguang.wu@...el.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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists