]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - lib/int_sqrt.c
kprobes: Prohibit probing on bsearch()
[mirror_ubuntu-bionic-kernel.git] / lib / int_sqrt.c
index db0b5aa071fc14e68fc3073e1a41c0d4617e65cf..e2d329099bf7483d2f09f48ade59e834cd6b7555 100644 (file)
@@ -8,12 +8,13 @@
 
 #include <linux/kernel.h>
 #include <linux/export.h>
+#include <linux/bitops.h>
 
 /**
- * int_sqrt - rough approximation to sqrt
+ * int_sqrt - computes the integer square root
  * @x: integer of which to calculate the sqrt
  *
- * A very rough approximation to the sqrt() function.
+ * Computes: floor(sqrt(x))
  */
 unsigned long int_sqrt(unsigned long x)
 {
@@ -22,7 +23,7 @@ unsigned long int_sqrt(unsigned long x)
        if (x <= 1)
                return x;
 
-       m = 1UL << (BITS_PER_LONG - 2);
+       m = 1UL << (__fls(x) & ~1UL);
        while (m != 0) {
                b = y + m;
                y >>= 1;