Re: [PATCH 3/3] devmem: cleanup unxlate_dev_mem_ptr() calls

From: Wu Fengguang
Date: Sat Sep 12 2009 - 10:57:32 EST


On Sat, Sep 12, 2009 at 08:05:00AM +0800, Andrew Morton wrote:
> On Fri, 11 Sep 2009 10:23:36 +0800
> Wu Fengguang <fengguang.wu@xxxxxxxxx> wrote:
>
> > No behavior change.
> >
> > CC: Marcelo Tosatti <mtosatti@xxxxxxxxxx>
> > CC: Greg Kroah-Hartman <gregkh@xxxxxxx>
> > CC: Mark Brown <broonie@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
> > CC: Johannes Berg <johannes@xxxxxxxxxxxxxxxx>
> > CC: Avi Kivity <avi@xxxxxxxxxxxx>
> > Signed-off-by: Wu Fengguang <fengguang.wu@xxxxxxxxx>
> > ---
> > drivers/char/mem.c | 13 +++++--------
> > 1 file changed, 5 insertions(+), 8 deletions(-)
> >
> > --- linux-mm.orig/drivers/char/mem.c 2009-09-10 21:59:39.000000000 +0800
> > +++ linux-mm/drivers/char/mem.c 2009-09-10 22:00:12.000000000 +0800
> > @@ -131,6 +131,7 @@ static ssize_t read_mem(struct file * fi
> > size_t count, loff_t *ppos)
> > {
> > unsigned long p = *ppos;
> > + unsigned long ret;
> > ssize_t read, sz;
> > char *ptr;
> >
> > @@ -169,12 +170,10 @@ static ssize_t read_mem(struct file * fi
> > if (!ptr)
> > return -EFAULT;
> >
> > - if (copy_to_user(buf, ptr, sz)) {
> > - unxlate_dev_mem_ptr(p, ptr);
> > - return -EFAULT;
> > - }
> > -
> > + ret = copy_to_user(buf, ptr, sz);
> > unxlate_dev_mem_ptr(p, ptr);
> > + if (ret)
> > + return -EFAULT;
> >
> > buf += sz;
> > p += sz;
>
> - local var `ret' didn't need function-wide scope. I think it's
> better to reduce its scope if poss.

OK.

> - conventionally the identifier `ret' refers to "the value which this
> function will return". Ditto `retval' and `rc'.

Good to know that, thanks!

> But that's not what `ret' does here so let's call it something
> else? `remaining' is rather verbose and formal, but accurate.
>
>
> --- a/drivers/char/mem.c~dev-mem-cleanup-unxlate_dev_mem_ptr-calls-fix
> +++ a/drivers/char/mem.c
> @@ -131,7 +131,6 @@ static ssize_t read_mem(struct file * fi
> size_t count, loff_t *ppos)
> {
> unsigned long p = *ppos;
> - unsigned long ret;

I got compile error because another place in read_mem() used ret.
I'll send you an updated fix.

Thanks,
Fengguang

> ssize_t read, sz;
> char *ptr;
>
> @@ -156,6 +155,8 @@ static ssize_t read_mem(struct file * fi
> #endif
>
> while (count > 0) {
> + unsigned long remaining;
> +
> sz = size_inside_page(p, count);
>
> if (!range_is_allowed(p >> PAGE_SHIFT, count))
> @@ -170,9 +171,9 @@ static ssize_t read_mem(struct file * fi
> if (!ptr)
> return -EFAULT;
>
> - ret = copy_to_user(buf, ptr, sz);
> + remaining = copy_to_user(buf, ptr, sz);
> unxlate_dev_mem_ptr(p, ptr);
> - if (ret)
> + if (remaining)
> return -EFAULT;
>
> buf += 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/