linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/gup_benchmark: fix unsigned comparison with less than zero
@ 2018-08-21 11:36 Colin King
  2018-08-21 12:24 ` Kirill A. Shutemov
  0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2018-08-21 11:36 UTC (permalink / raw)
  To: Andrew Morton, Kirill A . Shutemov, Michael S . Tsirkin, linux-mm
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently the return from get_user_pages_fast is being checked
to be less than zero for an error check, however, the variable being
checked is unsigned so the check is always false. Fix this by using
a signed long instead.

Detected by Coccinelle ("Unsigned expression compared with zero: nr <= 0")

Fixes: 64c349f4ae78 ("mm: add infrastructure for get_user_pages_fast() benchmarking")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 mm/gup_benchmark.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/mm/gup_benchmark.c b/mm/gup_benchmark.c
index 6a473709e9b6..a9a15e7a1185 100644
--- a/mm/gup_benchmark.c
+++ b/mm/gup_benchmark.c
@@ -31,6 +31,8 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
 	nr = gup->nr_pages_per_call;
 	start_time = ktime_get();
 	for (addr = gup->addr; addr < gup->addr + gup->size; addr = next) {
+		long n;
+
 		if (nr != gup->nr_pages_per_call)
 			break;
 
@@ -40,10 +42,10 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
 			nr = (next - addr) / PAGE_SIZE;
 		}
 
-		nr = get_user_pages_fast(addr, nr, gup->flags & 1, pages + i);
-		if (nr <= 0)
+		n = get_user_pages_fast(addr, nr, gup->flags & 1, pages + i);
+		if (n <= 0)
 			break;
-		i += nr;
+		i += n;
 	}
 	end_time = ktime_get();
 
-- 
2.17.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-08-21 12:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-21 11:36 [PATCH] mm/gup_benchmark: fix unsigned comparison with less than zero Colin King
2018-08-21 12:24 ` Kirill A. Shutemov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox