From: Wen Yang <wenyang@linux.alibaba.com>
To: rjw@rjwysocki.net, Len Brown <len.brown@intel.com>,
Pavel Machek <pavel@ucw.cz>
Cc: Wen Yang <wenyang@linux.alibaba.com>,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] kernel/power/snapshot.c: improve arithmetic divisions
Date: Fri, 3 Jan 2020 23:54:58 +0800 [thread overview]
Message-ID: <20200103155458.21707-1-wenyang@linux.alibaba.com> (raw)
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
next reply other threads:[~2020-01-03 15:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-03 15:54 Wen Yang [this message]
2020-01-07 11:43 ` [PATCH] kernel/power/snapshot.c: improve arithmetic divisions Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200103155458.21707-1-wenyang@linux.alibaba.com \
--to=wenyang@linux.alibaba.com \
--cc=len.brown@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=rjw@rjwysocki.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox