From: Arnd Bergmann <arnd@arndb.de> To: Andrew Morton <akpm@linux-foundation.org>, Michal Hocko <mhocko@suse.com>, "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> Cc: Arnd Bergmann <arnd@arndb.de>, Stephen Rothwell <sfr@canb.auug.org.au>, Vlastimil Babka <vbabka@suse.cz>, David Rientjes <rientjes@google.com>, Ingo Molnar <mingo@kernel.org>, Yang Shi <yang.s@alibaba-inc.com>, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm: thp: avoid uninitialized variable use Date: Fri, 15 Dec 2017 13:51:04 +0100 [thread overview] Message-ID: <20171215125129.2948634-1-arnd@arndb.de> (raw) 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] 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 <arnd@arndb.de> --- 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++; -- 2.9.0
WARNING: multiple messages have this Message-ID (diff)
From: Arnd Bergmann <arnd@arndb.de> To: Andrew Morton <akpm@linux-foundation.org>, Michal Hocko <mhocko@suse.com>, "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> Cc: Arnd Bergmann <arnd@arndb.de>, Stephen Rothwell <sfr@canb.auug.org.au>, Vlastimil Babka <vbabka@suse.cz>, David Rientjes <rientjes@google.com>, Ingo Molnar <mingo@kernel.org>, Yang Shi <yang.s@alibaba-inc.com>, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm: thp: avoid uninitialized variable use Date: Fri, 15 Dec 2017 13:51:04 +0100 [thread overview] Message-ID: <20171215125129.2948634-1-arnd@arndb.de> (raw) 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] 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 <arnd@arndb.de> --- 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++; -- 2.9.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next reply other threads:[~2017-12-15 12:53 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2017-12-15 12:51 Arnd Bergmann [this message] 2017-12-15 12:51 ` [PATCH] mm: thp: avoid uninitialized variable use Arnd Bergmann 2017-12-15 13:03 ` Michal Hocko 2017-12-15 13:03 ` Michal Hocko 2017-12-15 18:01 ` Yang Shi 2017-12-15 18:01 ` Yang Shi 2017-12-16 12:24 ` Arnd Bergmann 2017-12-16 12:24 ` Arnd Bergmann 2017-12-16 22:25 ` Yang Shi 2017-12-16 22:25 ` Yang Shi
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20171215125129.2948634-1-arnd@arndb.de \ --to=arnd@arndb.de \ --cc=akpm@linux-foundation.org \ --cc=kirill.shutemov@linux.intel.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=mhocko@suse.com \ --cc=mingo@kernel.org \ --cc=rientjes@google.com \ --cc=sfr@canb.auug.org.au \ --cc=vbabka@suse.cz \ --cc=yang.s@alibaba-inc.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.