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