lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20090911170047.94de0896.akpm@linux-foundation.org>
Date:	Fri, 11 Sep 2009 17:00:47 -0700
From:	Andrew Morton <akpm@...ux-foundation.org>
To:	Wu Fengguang <fengguang.wu@...el.com>
Cc:	mtosatti@...hat.com, gregkh@...e.de,
	broonie@...nsource.wolfsonmicro.com, johannes@...solutions.net,
	avi@...ranet.com, fengguang.wu@...el.com, andi@...stfloor.org,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/3] devmem: remove redundant test on len

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.


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.

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


--
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

Powered by Openwall GNU/*/Linux Powered by OpenVZ