]> git.karo-electronics.de Git - linux-beck.git/commitdiff
fs/proc/vmcore.c: put if tests in the top of the while loop to reduce duplication
authorZhang Yanfei <zhangyanfei@cn.fujitsu.com>
Thu, 28 Feb 2013 01:03:17 +0000 (17:03 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 28 Feb 2013 03:10:11 +0000 (19:10 -0800)
In read_vmcore() two `if' tests are duplicated.  Change the position of
them could reduce the duplication.  This change does not affect the
behaviour of the function.

[akpm@linux-foundation.org: avoid `if (foo = bar)' thing, use min_t()]
[akpm@linux-foundation.org: s/max_t/min_t/]
Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/proc/vmcore.c

index 41dd018f72dd00ca1885a34fec2bfc21c94f9a44..b870f740ab5a5bb2bf92451fe3b71a81d1f16a17 100644 (file)
@@ -176,15 +176,15 @@ 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) {
+               tsz = min_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));
+               if (tsz > nr_bytes)
+                       tsz = nr_bytes;
+
                tmp = read_from_oldmem(buffer, tsz, &start, 1);
                if (tmp < 0)
                        return tmp;
@@ -199,12 +199,6 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
                                                struct vmcore, list);
                        start = curr_m->paddr;
                }
-               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;
        }
        return acc;
 }