linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kernel/power/snapshot.c: improve arithmetic divisions
@ 2020-01-03 15:54 Wen Yang
  2020-01-07 11:43 ` Rafael J. Wysocki
  0 siblings, 1 reply; 2+ messages in thread
From: Wen Yang @ 2020-01-03 15:54 UTC (permalink / raw)
  To: rjw, Len Brown, Pavel Machek; +Cc: Wen Yang, linux-pm, linux-kernel

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>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Len Brown <len.brown@intel.com>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 kernel/power/snapshot.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
index 26b9168..8a6eaf7 100644
--- a/kernel/power/snapshot.c
+++ b/kernel/power/snapshot.c
@@ -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,
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] kernel/power/snapshot.c: improve arithmetic divisions
  2020-01-03 15:54 [PATCH] kernel/power/snapshot.c: improve arithmetic divisions Wen Yang
@ 2020-01-07 11:43 ` Rafael J. Wysocki
  0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2020-01-07 11:43 UTC (permalink / raw)
  To: Wen Yang
  Cc: Rafael J. Wysocki, Len Brown, Pavel Machek, Linux PM,
	Linux Kernel Mailing List

On Fri, Jan 3, 2020 at 4:55 PM Wen Yang <wenyang@linux.alibaba.com> wrote:
>
> 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>
> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
> Cc: Len Brown <len.brown@intel.com>
> Cc: Pavel Machek <pavel@ucw.cz>
> Cc: linux-pm@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
>  kernel/power/snapshot.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
> index 26b9168..8a6eaf7 100644
> --- a/kernel/power/snapshot.c
> +++ b/kernel/power/snapshot.c
> @@ -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,
> --

Applied as 5.6 material under a new subject ("PM: hibernate: improve
arithmetic division in preallocate_highmem_fraction()"), thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-01-07 11:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-03 15:54 [PATCH] kernel/power/snapshot.c: improve arithmetic divisions Wen Yang
2020-01-07 11:43 ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).