Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756164AbdLOSB2 (ORCPT ); Fri, 15 Dec 2017 13:01:28 -0500 Received: from out0-205.mail.aliyun.com ([140.205.0.205]:35612 "EHLO out0-205.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755848AbdLOSB1 (ORCPT ); Fri, 15 Dec 2017 13:01:27 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R211e4;CH=green;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04463;MF=yang.s@alibaba-inc.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---.9jWEYH1_1513360870; Subject: Re: [PATCH] mm: thp: avoid uninitialized variable use To: Arnd Bergmann , Andrew Morton , Michal Hocko , "Kirill A. Shutemov" Cc: Stephen Rothwell , Vlastimil Babka , David Rientjes , Ingo Molnar , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20171215125129.2948634-1-arnd@arndb.de> From: "Yang Shi" Message-ID: <8d5476e2-5f87-1134-62d4-9f649c4e709a@alibaba-inc.com> Date: Sat, 16 Dec 2017 02:01:08 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20171215125129.2948634-1-arnd@arndb.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1708 Lines: 51 On 12/15/17 4:51 AM, Arnd Bergmann wrote: > When the down_read_trylock() fails, 'vma' has not been initialized > yet, which gcc now warns about: > > mm/khugepaged.c: In function 'khugepaged': > mm/khugepaged.c:1659:25: error: 'vma' may be used uninitialized in this function [-Werror=maybe-uninitialized] Arnd, Thanks for catching this. I'm wondering why my test didn't catch it. It might be because my gcc is old. I'm using gcc 4.8.5 on centos 7. Regards, Yang > > Presumable we are not supposed to call find_vma() without the mmap_sem > either, so setting it to NULL for this case seems appropriate. > > Fixes: 0951b59acf3a ("mm: thp: use down_read_trylock() in khugepaged to avoid long block") > Signed-off-by: Arnd Bergmann > --- > I'm not completely sure this patch is sufficient, it gets rid of > the warning, but it would be good to have the code reviewed better > to see if other problems remain that result from down_read_trylock() > patch. > --- > mm/khugepaged.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index 521b908f9600..b7e2268dfc9a 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -1677,11 +1677,10 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, > * Don't wait for semaphore (to avoid long wait times). Just move to > * the next mm on the list. > */ > + vma = NULL; > if (unlikely(!down_read_trylock(&mm->mmap_sem))) > goto breakouterloop_mmap_sem; > - if (unlikely(khugepaged_test_exit(mm))) > - vma = NULL; > - else > + if (likely(!khugepaged_test_exit(mm))) > vma = find_vma(mm, khugepaged_scan.address); > > progress++; >