lkml.org 
[lkml]   [2019]   [Jan]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v3 1/1] int_sqrt() adjustments
Date
Add __attribute_const__ and adjust to use (signed) int for the right param of "<<".
Change the return value of int_sqrt() from "unsigned long" to u32 to be
the same as int_sqrt64() and adjust some calling functions.

Signed-off-by: Florian La Roche <Florian.LaRoche@gmail.com>
---
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 8 ++++----
drivers/media/pci/cx88/cx88-dsp.c | 2 +-
include/linux/kernel.h | 4 ++--
lib/int_sqrt.c | 8 ++++----
lib/prime_numbers.c | 2 +-
mm/vmscan.c | 2 +-
6 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
index a9ed0ecc94e2..460ef38d9667 100644
--- a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
@@ -348,7 +348,7 @@ static int fill_hole(struct drm_i915_private *i915,
struct drm_i915_gem_object *obj;
const unsigned long max_pages =
min_t(u64, ULONG_MAX - 1, hole_size/2 >> PAGE_SHIFT);
- const unsigned long max_step = max(int_sqrt(max_pages), 2UL);
+ const u32 max_step = max(int_sqrt(max_pages), 2UL);
unsigned long npages, prime, flags;
struct i915_vma *vma;
LIST_HEAD(objects);
@@ -400,7 +400,7 @@ static int fill_hole(struct drm_i915_private *i915,

err = i915_vma_pin(vma, 0, 0, offset | flags);
if (err) {
- pr_err("%s(%s) pin (forward) failed with err=%d on size=%lu pages (prime=%lu), offset=%llx\n",
+ pr_err("%s(%s) pin (forward) failed with err=%d on size=%lu pages (prime=%u), offset=%llx\n",
__func__, p->name, err, npages, prime, offset);
goto err;
}
@@ -473,7 +473,7 @@ static int fill_hole(struct drm_i915_private *i915,

err = i915_vma_pin(vma, 0, 0, offset | flags);
if (err) {
- pr_err("%s(%s) pin (backward) failed with err=%d on size=%lu pages (prime=%lu), offset=%llx\n",
+ pr_err("%s(%s) pin (backward) failed with err=%d on size=%lu pages (prime=%u), offset=%llx\n",
__func__, p->name, err, npages, prime, offset);
goto err;
}
@@ -533,7 +533,7 @@ static int fill_hole(struct drm_i915_private *i915,
}
}

- if (igt_timeout(end_time, "%s timed out (npages=%lu, prime=%lu)\n",
+ if (igt_timeout(end_time, "%s timed out (npages=%lu, prime=%u)\n",
__func__, npages, prime)) {
err = -EINTR;
goto err;
diff --git a/drivers/media/pci/cx88/cx88-dsp.c b/drivers/media/pci/cx88/cx88-dsp.c
index 105029088120..563a298f2ac0 100644
--- a/drivers/media/pci/cx88/cx88-dsp.c
+++ b/drivers/media/pci/cx88/cx88-dsp.c
@@ -137,7 +137,7 @@ static u32 freq_magnitude(s16 x[], u32 N, u32 freq)
{
u32 sum = int_goertzel(x, N, freq);

- return (u32)int_sqrt(sum);
+ return int_sqrt(sum);
}

static u32 noise_magnitude(s16 x[], u32 N, u32 freq_start, u32 freq_end)
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 8f0e68e250a7..796027bbf1b8 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__ u32 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..43b0158dd901 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__ u32 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;
diff --git a/lib/prime_numbers.c b/lib/prime_numbers.c
index 550eec457c2e..96c7ef08f379 100644
--- a/lib/prime_numbers.c
+++ b/lib/prime_numbers.c
@@ -67,7 +67,7 @@ static unsigned long selftest_max;

static bool slow_is_prime_number(unsigned long x)
{
- unsigned long y = int_sqrt(x);
+ u32 y = int_sqrt(x);

while (y > 1) {
if ((x % y) == 0)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index a714c4f800e9..0b9abe1de9e7 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -2216,7 +2216,7 @@ static bool inactive_list_is_low(struct lruvec *lruvec, bool file,
struct pglist_data *pgdat = lruvec_pgdat(lruvec);
enum lru_list inactive_lru = file * LRU_FILE;
unsigned long inactive, active;
- unsigned long inactive_ratio;
+ u32 inactive_ratio;
unsigned long refaults;
unsigned long gb;

--
2.17.1
\
 
 \ /
  Last update: 2019-01-27 22:34    [W:0.038 / U:1.028 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site