OSDN Git Service

PM: hibernate: improve arithmetic division in preallocate_highmem_fraction()
authorWen Yang <wenyang@linux.alibaba.com>
Fri, 3 Jan 2020 15:54:58 +0000 (23:54 +0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 7 Jan 2020 11:42:56 +0000 (12:42 +0100)
do_div() does a 64-by-32 division. Use div64_u64() instead of
do_div() if the divisor is u64, to avoid truncation to 32-bit.

This change also cleans up code a tad.

Signed-off-by: Wen Yang <wenyang@linux.alibaba.com>
[ rjw: Subject ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
kernel/power/snapshot.c

index 26b9168..8a6eaf7 100644 (file)
@@ -1566,9 +1566,7 @@ static unsigned long preallocate_image_highmem(unsigned long nr_pages)
  */
 static unsigned long __fraction(u64 x, u64 multiplier, u64 base)
 {
-       x *= multiplier;
-       do_div(x, base);
-       return (unsigned long)x;
+       return div64_u64(x * multiplier, base);
 }
 
 static unsigned long preallocate_highmem_fraction(unsigned long nr_pages,