From patchwork Thu Oct 4 21:14:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10626759 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 31DE316B1 for ; Thu, 4 Oct 2018 21:15:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 213AF293B1 for ; Thu, 4 Oct 2018 21:15:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 14A48295AC; Thu, 4 Oct 2018 21:15:22 +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,UNPARSEABLE_RELAY 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 9A007293B1 for ; Thu, 4 Oct 2018 21:15:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 94F766B0010; Thu, 4 Oct 2018 17:15:20 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8FE626B0266; Thu, 4 Oct 2018 17:15:20 -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 814AD6B0269; Thu, 4 Oct 2018 17:15:20 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id 45E116B0010 for ; Thu, 4 Oct 2018 17:15:20 -0400 (EDT) Received: by mail-pf1-f197.google.com with SMTP id d22-v6so7341590pfn.3 for ; Thu, 04 Oct 2018 14:15:20 -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; bh=74647uHGjqR09NCtkBRofAJku/T/0sqkgzrbFs8/X7g=; b=BF1qiRJ3Aonw6GxqOfuR6d56lgjoyWG8/y0Sjt2i5yadtQDxbjtWkDG6Xcul35JWWr Gb7dRn9g103y768Q30A5BbXNgxemRBnNFWxr+rGxw0h2vfoUSYy1pwFH1zo85StpRIyp lI2fpmP78zw6zW+fgd15UrLOJQiGqU/xMC3mqrckYQ3n9UGbLfQFU8Uh2dDiiwdfQZxs 8GYasyLcj2Qg3ZX2wIT/jHPohoi0w+6cVGYaNm/fcQBwEm6kb6iEYwfGjr8zRck7nLH1 UwNMGa64UwPz9dA58K7inbT0g8i9GbXH4fCk8KFeTsethn0d5fq/7AiuTDh6BIY/yPN7 1PWA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Gm-Message-State: ABuFfogCJwPfmaRotVUmtG2Y+0QCUdcG7vzrlPCWnQUqs+tXgplzTXc0 uzovglbEXRjSbLhvOdyu8+tKVH67HKbUoKnWpw0Gjev3+A1eWxvqKnPwJtNDnNnAr7+296DdvXH wx2+oQuf5pMcD72WJz+FS6+rGTBV6m/Gn25eeJUQqaeh0KORshm9yew0lBJOwpmfe3A== X-Received: by 2002:a17:902:a716:: with SMTP id w22-v6mr8326473plq.334.1538687719966; Thu, 04 Oct 2018 14:15:19 -0700 (PDT) X-Google-Smtp-Source: ACcGV61xoBbG6qVbH1DpimR4TS2GT+CPm09TpnDmzE+62V+MD4YszwIywT9mv1NCdig08a5ZBy7+ X-Received: by 2002:a17:902:a716:: with SMTP id w22-v6mr8326438plq.334.1538687719269; Thu, 04 Oct 2018 14:15:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538687719; cv=none; d=google.com; s=arc-20160816; b=fJmJdTny6mxk/j8EuJfTLURZvFT12dKz0kNOtjibB67liCfvR12GHHjyxvrM1W8P32 DKGe44tK8V/5AvvqDPEH/cnKH7uoJK3V0GUdc6einrOse/ahei+E5NX5YtzjEuTzgsEy Jnz0syRb7XzxFefXiACbnF8AygjuK5Begcv5mFGkUyb34JSpu0xiLitRRJFept64i3R3 O4ln/BPbKbmg3v+MFayD2KR0beckdEvpCZfFPdHkdUPVspCiIkKSVA0NtpeAVkRTK60v 4fHBNw9QsHONpqpQxrlyZ3NxK7w0Hu0l4hd6RJCPA7emBtysngIbj6T3auSWqH3RbT+M 0BmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from; bh=74647uHGjqR09NCtkBRofAJku/T/0sqkgzrbFs8/X7g=; b=GKpg9k+CuFMaeJsiOJ6MOQe7+vfHHdEWfh1GVue7lXTessHCcl4aeEetjExNkdvW1w DTxppV7j1LQzaQuHMeGlVCqyoJ0BPhD2D+WukXbp55B7rjWDuqhTuWb5MVlhxVeuthnx giehc8aaEFcAeXKpsATf3A5ruiEKA7LAxmOM4h50Ta0o6mN9ebgML5387WG/VdatnzOH HeQm15YxAkL46lHn16yiT4v91hkRpHr5o+hLRx8Xyv5dIrhFAuJJ/aiDhKzZlOCTXlG1 EXyPjRmyvXuyUQ+5wryECpIpvn9otOGEzZ9rwmhl1MR/8OgIYJx5hRdS08Me7BhUxUi5 q0sQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out4436.biz.mail.alibaba.com (out4436.biz.mail.alibaba.com. [47.88.44.36]) by mx.google.com with ESMTPS id s17-v6si4940902pgm.317.2018.10.04.14.15.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Oct 2018 14:15:19 -0700 (PDT) Received-SPF: pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) client-ip=47.88.44.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R931e4;CH=green;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04390;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0T9zY.5M_1538687672; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0T9zY.5M_1538687672) by smtp.aliyun-inc.com(127.0.0.1); Fri, 05 Oct 2018 05:14:40 +0800 From: Yang Shi To: vbabka@suse.cz, kirill.shutemov@linux.intel.com, mhocko@kernel.org, willy@infradead.org, ldufour@linux.vnet.ibm.com, colin.king@canonical.com, akpm@linux-foundation.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2 -mm] mm: brk: fix unsigned compare against 0 issue Date: Fri, 5 Oct 2018 05:14:31 +0800 Message-Id: <1538687672-17795-1-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 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 Static analysis reported unsigned compare against 0 issue according to Colin Ian King. Defined an int temp variable to check the return value of __do_munmap(). Reported-by: Colin Ian King Cc: Vlastimil Babka Cc: Kirill A. Shutemov Cc: Michal Hocko Cc: Matthew Wilcox Cc: Laurent Dufour Cc: Andrew Morton Signed-off-by: Yang Shi --- Andrew, this should be able to be folded into the original patch. mm/mmap.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 68dc4fb..c78f7e9 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -242,17 +242,18 @@ static int do_brk_flags(unsigned long addr, unsigned long request, unsigned long * __do_munmap() may downgrade mmap_sem to read. */ if (brk <= mm->brk) { + int ret; /* * mm->brk need to be protected by write mmap_sem, update it * before downgrading mmap_sem. * When __do_munmap fail, it will be restored from origbrk. */ mm->brk = brk; - retval = __do_munmap(mm, newbrk, oldbrk-newbrk, &uf, true); - if (retval < 0) { + ret = __do_munmap(mm, newbrk, oldbrk-newbrk, &uf, true); + if (ret < 0) { mm->brk = origbrk; goto out; - } else if (retval == 1) + } else if (ret == 1) downgraded = true; goto success; }