Skip to contentSkip to conversation

int_sqrt() adjustments

PATCH Superseded Florian La Roche 2 participants 3 messages Jan 27, 2019 Library code

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 int_sqrt() adjustments

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

---
 include/linux/kernel.h | 4 ++--
 lib/int_sqrt.c         | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)
include/linux/kernel.h +2 -2
index 8f0e68e250a7..df03a3cca309 100644
@@ -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)
 {
lib/int_sqrt.c +4 -4
index 30e0f9770f88..fd249238fd31 100644
@@ -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;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 1 line · Florian La Roche

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

[]

include/linux/kernel.h

Quoted 1 line
include/linux/kernel.h +0 -0

[]

include/linux/kernel.h extern int __kernel_text_address(unsigned long addr); · line 516

Quoted 6 lines
include/linux/kernel.h +1 -1
@@ -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);

This might as well return u32 to be consistent with int_sqrt64

#2 lore raw

Hello Joe,

sending in a new patch with u32 as return value and some adjusted callers of int_sqrt().

best regards,

Florian La Roche