From patchwork Tue Aug 21 11:36:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 10571395 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CB2B25A4 for ; Tue, 21 Aug 2018 11:36:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C1E4C29EB3 for ; Tue, 21 Aug 2018 11:36:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B5B3929EBC; Tue, 21 Aug 2018 11:36:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85A0229EC2 for ; Tue, 21 Aug 2018 11:36:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5BD486B1E77; Tue, 21 Aug 2018 07:36:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 56CD26B1E78; Tue, 21 Aug 2018 07:36:39 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 45C346B1E79; Tue, 21 Aug 2018 07:36:39 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm0-f70.google.com (mail-wm0-f70.google.com [74.125.82.70]) by kanga.kvack.org (Postfix) with ESMTP id DC0DF6B1E78 for ; Tue, 21 Aug 2018 07:36:38 -0400 (EDT) Received: by mail-wm0-f70.google.com with SMTP id m129-v6so2072948wma.8 for ; Tue, 21 Aug 2018 04:36:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:mime-version:content-transfer-encoding; bh=9RlbfyjQ5Do3yDT5m8oqNMNcKVIGX2m1bIO6kPYw1bo=; b=D70WlUmS9HaieI8ZgOq7NIi15mQXDgDGo7XlYyyKco2U59/DjGwpXHYmIWAjgqldFP twDDTvayko5nlgOIYyamS0D2keDwTmj/Y7rEb48nwQgi7B1RMpcXTj3ksLZcDVbsg0pJ uSP5iz+tn4KNYxs/84TYUSTwxCC3FrbQjvJ+Vokn47pZHg3V1nwGT4UoQxwdRfR4Wp9r RYYCUJc1AFDe6CUOX1cm6IxdP3e38t1TJvosjr/msgGwtoFLMsYtIWJhbNG5vxpKeuYe asI3MDQ7WXykE3AXol5jNIEkMnlpXJPsVqxZ/p97f1HYeo8mJczTLeiT2ZFb3ZLPT8PC pDgg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of colin.king@canonical.com designates 91.189.89.112 as permitted sender) smtp.mailfrom=colin.king@canonical.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com X-Gm-Message-State: AOUpUlEJtnmHWWhJYrdrAu1Er8lVxqsxdYek7ZNqaxsCI5iIB6b7jcjN xaB3eutmA07f4oo++l0gT9eME01ya0gnoJZWE1MGlzXpEaGuXEMGK/s/tSD2zzxLIkTjASkEBto Lz40ZGotJUJLOdgO4+olSamR5VbTooQjaZldam5etJYmemh8fiCWMZmRyFM7U8vi0mw== X-Received: by 2002:a1c:28c2:: with SMTP id o185-v6mr28411088wmo.40.1534851398241; Tue, 21 Aug 2018 04:36:38 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyLIaq+tImRfnjbqjNhcu1AAEZNycfey4+3rU6TM0FjfPmuTAG8xTRh4xhJu22EKEnf9XBs X-Received: by 2002:a1c:28c2:: with SMTP id o185-v6mr28411056wmo.40.1534851397366; Tue, 21 Aug 2018 04:36:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534851397; cv=none; d=google.com; s=arc-20160816; b=x43GMz88EJIrz30vFy9Mz0sgfU97Yu7S2b4VlAYs27BRrJqoyENTXpV0qIgNffm/5a 75oikmdYwIkHEdmiul5ByvIMwxqfaDca7olAHjrfvOT/2v2imRu0nLZC4vHWLamkxKyZ /TnaAmsv10P466/BHX/mLtzYXMDMz1ByfDe/kJri5f0irBmqR3zLl6En9Q8+6lhGpUdI ugFcJJFi8JKbSxtpUBlTXLDqbX3jdbOFMC6aM/JFIFP9QWlzhU7LSomNbfA/fChB8Ywu TjlriBKITdni+wsc8YbxQ03q0b8BHUqIVG6NtZK7IdzrNIfBWPc+DNSOK9258hh9sfkD 1NCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=9RlbfyjQ5Do3yDT5m8oqNMNcKVIGX2m1bIO6kPYw1bo=; b=X6tSRq+O+C1EDskkvCMlEBugNaOx+5zsloYf8G8ZayZoBkfbko2RPgmwcTTGETke4Z wbq3ITfnSN7nZJciBHJG9XDuZn+E6KQnN0k7xEQaPMa2jKh7umyrd9d6Qu6qAgc+eC3u CnWUlgJ0H+2OOx5hjqkQTr4TEjqM1t6i7FYOuVX2kdMLmS80DwFQzbv3GPWQYlR6E2BS r7eBJ0AyMyXzQ3torwVzm7H61mOHT/pXVsOx7dp/2r1EdSZf3iMnneqPclbHz4X5ui6m U+eJMldeSqZbzdRdETtePWwfLVeKAcGeza2nR6LOriNR7im5ecV4XFrBos4uaR39m2LG dcaQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of colin.king@canonical.com designates 91.189.89.112 as permitted sender) smtp.mailfrom=colin.king@canonical.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: from youngberry.canonical.com (youngberry.canonical.com. [91.189.89.112]) by mx.google.com with ESMTPS id x17-v6si7819028wrv.92.2018.08.21.04.36.37 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 21 Aug 2018 04:36:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of colin.king@canonical.com designates 91.189.89.112 as permitted sender) client-ip=91.189.89.112; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of colin.king@canonical.com designates 91.189.89.112 as permitted sender) smtp.mailfrom=colin.king@canonical.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1fs4xe-0007rQ-HM; Tue, 21 Aug 2018 11:36:34 +0000 From: Colin King To: Andrew Morton , "Kirill A . Shutemov" , "Michael S . Tsirkin" , linux-mm@kvack.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/gup_benchmark: fix unsigned comparison with less than zero Date: Tue, 21 Aug 2018 12:36:34 +0100 Message-Id: <20180821113634.3782-1-colin.king@canonical.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Colin Ian King 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 --- 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();