From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74352CA9EB3 for ; Fri, 18 Oct 2019 02:01:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EF44621D7C for ; Fri, 18 Oct 2019 02:01:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EF44621D7C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 591718E0005; Thu, 17 Oct 2019 22:01:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 542778E0003; Thu, 17 Oct 2019 22:01:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4307C8E0005; Thu, 17 Oct 2019 22:01:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 23B668E0003 for ; Thu, 17 Oct 2019 22:01:57 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id ADDFF82C2B69 for ; Fri, 18 Oct 2019 02:01:56 +0000 (UTC) X-FDA: 76055254632.20.game21_108d32284d437 X-HE-Tag: game21_108d32284d437 X-Filterd-Recvd-Size: 3359 Received: from huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf42.hostedemail.com (Postfix) with ESMTP for ; Fri, 18 Oct 2019 02:01:53 +0000 (UTC) Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 23B89227446243984D79; Fri, 18 Oct 2019 10:01:49 +0800 (CST) Received: from [127.0.0.1] (10.177.29.68) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.439.0; Fri, 18 Oct 2019 10:01:48 +0800 Message-ID: <5DA91D0B.7050009@huawei.com> Date: Fri, 18 Oct 2019 10:01:47 +0800 From: zhong jiang User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 MIME-Version: 1.0 To: Ira Weiny CC: , , , Subject: Re: [PATCH] mm: Unsigned 'nr_pages' always larger than zero References: <1571282386-65076-1-git-send-email-zhongjiang@huawei.com> <20191017180148.GA19348@iweiny-DESK2.sc.intel.com> In-Reply-To: <20191017180148.GA19348@iweiny-DESK2.sc.intel.com> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.29.68] X-CFilter-Loop: Reflected 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: On 2019/10/18 2:01, Ira Weiny wrote: > On Thu, Oct 17, 2019 at 11:19:46AM +0800, zhong jiang wrote: >> With the help of unsigned_lesser_than_zero.cocci. Unsigned 'nr_pages"' >> compare with zero. And __get_user_pages_locked will return an long value. >> >> The patch use a new local variable to store the return value of >> __get_user_pages_locked(). Then use it to compare with zero. >> >> Suggested-by: Andrew Morton >> Signed-off-by: zhong jiang >> --- >> mm/gup.c | 8 +++++--- >> 1 file changed, 5 insertions(+), 3 deletions(-) >> >> diff --git a/mm/gup.c b/mm/gup.c >> index 8f236a3..1fe0ceb 100644 >> --- a/mm/gup.c >> +++ b/mm/gup.c >> @@ -1443,6 +1443,7 @@ static long check_and_migrate_cma_pages(struct task_struct *tsk, >> bool drain_allow = true; >> bool migrate_allow = true; >> LIST_HEAD(cma_page_list); >> + long ret; >> >> check_again: >> for (i = 0; i < nr_pages;) { >> @@ -1504,17 +1505,18 @@ static long check_and_migrate_cma_pages(struct task_struct *tsk, >> * again migrating any new CMA pages which we failed to isolate >> * earlier. >> */ >> - nr_pages = __get_user_pages_locked(tsk, mm, start, nr_pages, >> + ret = __get_user_pages_locked(tsk, mm, start, nr_pages, >> pages, vmas, NULL, >> gup_flags); >> >> - if ((nr_pages > 0) && migrate_allow) { >> + nr_pages = ret; > I think if ret is negative we want to return the error here. I think the code works. Because we alway return the ret. we will return the error value if the ret is negative . >> + if ((ret > 0) && migrate_allow) { >> drain_allow = true; >> goto check_again; >> } >> } >> >> - return nr_pages; >> + return ret; > If the cma_page_list is empty doesn't this return uninitialized data? You're right. I miss that. Thanks for pointing out. Sincerely, zhong jiang > Ira > >> } >> #else >> static long check_and_migrate_cma_pages(struct task_struct *tsk, >> -- >> 1.7.12.4 >> >> > . >