mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Florian La Roche <florian.laroche@googlemail.com>
To: linux-kernel@vger.kernel.org
Cc: Crt Mori <cmo@melexis.com>, Joe Perches <joe@perches.com>,
	Davidlohr Bueso <dave@stgolabs.net>,
	Will Deacon <will.deacon@arm.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Florian La Roche <Florian.LaRoche@gmail.com>
Subject: [PATCH v2 1/1] int_sqrt() adjustments
Date: Sun, 27 Jan 2019 21:32:39 +0100	[thread overview]
Message-ID: <20190127203239.973-1-Florian.LaRoche@gmail.com> (raw)

Add __attribute_const__ and use normal ints for the right param of "<<".

Signed-off-by: Florian La Roche <Florian.LaRoche@gmail.com>
---
 include/linux/kernel.h | 4 ++--
 lib/int_sqrt.c         | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 8f0e68e250a7..df03a3cca309 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -513,10 +513,10 @@ extern int __kernel_text_address(unsigned long addr);
 extern int kernel_text_address(unsigned long addr);
 extern int func_ptr_is_kernel_text(void *ptr);
 
-unsigned long int_sqrt(unsigned long);
+__attribute_const__ unsigned long int_sqrt(unsigned long);
 
 #if BITS_PER_LONG < 64
-u32 int_sqrt64(u64 x);
+__attribute_const__ u32 int_sqrt64(u64 x);
 #else
 static inline u32 int_sqrt64(u64 x)
 {
diff --git a/lib/int_sqrt.c b/lib/int_sqrt.c
index 30e0f9770f88..fd249238fd31 100644
--- a/lib/int_sqrt.c
+++ b/lib/int_sqrt.c
@@ -16,14 +16,14 @@
  *
  * Computes: floor(sqrt(x))
  */
-unsigned long int_sqrt(unsigned long x)
+__attribute_const__ unsigned long int_sqrt(unsigned long x)
 {
 	unsigned long b, m, y = 0;
 
 	if (x <= 1)
 		return x;
 
-	m = 1UL << (__fls(x) & ~1UL);
+	m = 1UL << (__fls(x) & ~1);
 	while (m != 0) {
 		b = y + m;
 		y >>= 1;
@@ -45,14 +45,14 @@ EXPORT_SYMBOL(int_sqrt);
  * is expected.
  * @x: 64bit integer of which to calculate the sqrt
  */
-u32 int_sqrt64(u64 x)
+__attribute_const__ u32 int_sqrt64(u64 x)
 {
 	u64 b, m, y = 0;
 
 	if (x <= ULONG_MAX)
 		return int_sqrt((unsigned long) x);
 
-	m = 1ULL << ((fls64(x) - 1) & ~1ULL);
+	m = 1ULL << ((fls64(x) - 1) & ~1);
 	while (m != 0) {
 		b = y + m;
 		y >>= 1;
-- 
2.17.1


             reply	other threads:[~2019-01-27 20:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-27 20:32 Florian La Roche [this message]
2019-01-27 20:46 ` Joe Perches
2019-01-27 21:21   ` Florian La Roche

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=20190127203239.973-1-Florian.LaRoche@gmail.com \
    --to=florian.laroche@googlemail.com \
    --cc=Florian.LaRoche@gmail.com \
    --cc=cmo@melexis.com \
    --cc=dave@stgolabs.net \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=torvalds@linux-foundation.org \
    --cc=will.deacon@arm.com \
    /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

all inboxes | Powered by JetHome®