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: <20130207160620.6c8f93d4.akpm@linux-foundation.org>
Date:	Thu, 7 Feb 2013 16:06:20 -0800
From:	Andrew Morton <akpm@...ux-foundation.org>
To:	Zhang Yanfei <zhangyanfei.yes@...il.com>
Cc:	"Eric W. Biederman" <ebiederm@...ssion.com>,
	benh@...nel.crashing.org, mahesh@...ux.vnet.ibm.com,
	zhangyanfei@...fujitsu.com, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] fs/proc/vmcore.c: Put if tests in the top of the while
 loop to reduce duplication

On Sun, 03 Feb 2013 21:13:36 +0800
Zhang Yanfei <zhangyanfei.yes@...il.com> wrote:

> From: Zhang Yanfei <zhangyanfei@...fujitsu.com>
> 
> In function read_vmcore, two if tests are duplicate. Change the position
> of them could reduce the duplication. This change does not affect
> the behaviour of the function.
> 

hm, yes.

> --- a/fs/proc/vmcore.c
> +++ b/fs/proc/vmcore.c
> @@ -175,15 +175,16 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
>  	start = map_offset_to_paddr(*fpos, &vmcore_list, &curr_m);
>  	if (!curr_m)
>          	return -EINVAL;
> -	if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
> -		tsz = buflen;
> -
> -	/* Calculate left bytes in current memory segment. */
> -	nr_bytes = (curr_m->size - (start - curr_m->paddr));
> -	if (tsz > nr_bytes)
> -		tsz = nr_bytes;
>  
>  	while (buflen) {
> +		if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
> +			tsz = buflen;
> +
> +		/* Calculate left bytes in current memory segment. */
> +		nr_bytes = (curr_m->size - (start - curr_m->paddr));
> +		if (tsz > nr_bytes)
> +			tsz = nr_bytes;
> +
>  		tmp = read_from_oldmem(buffer, tsz, &start, 1);
>  		if (tmp < 0)
>  			return tmp;
> @@ -198,12 +199,6 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
>  						struct vmcore, list);
>  			start = curr_m->paddr;

`start' gets changed here

>  		}
> -		if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
> -			tsz = buflen;
> -		/* Calculate left bytes in current memory segment. */
> -		nr_bytes = (curr_m->size - (start - curr_m->paddr));
> -		if (tsz > nr_bytes)
> -			tsz = nr_bytes;

So this code can calcualte a different value of `tsz'.  But that won't
get used.  Looks right to me.

>  	}
>  	return acc;
>  }

While we're there, let's squish that assignment-in-a-if pestilence and
use max_t().

--- a/fs/proc/vmcore.c~fs-proc-vmcorec-put-if-tests-in-the-top-of-the-while-loop-to-reduce-duplication-fix
+++ a/fs/proc/vmcore.c
@@ -178,8 +178,7 @@ static ssize_t read_vmcore(struct file *
         	return -EINVAL;
 
 	while (buflen) {
-		if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
-			tsz = buflen;
+		tsz = max_t(size_t, buflen, PAGE_SIZE - (start & ~PAGE_MASK));
 
 		/* Calculate left bytes in current memory segment. */
 		nr_bytes = (curr_m->size - (start - curr_m->paddr));
_

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