linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/khugepaged: Initialize index and nr in collapse_file()
@ 2022-10-25 17:34 Nathan Chancellor
  2022-10-25 20:23 ` Zach O'Keefe
  2022-10-26  1:48 ` Andrew Morton
  0 siblings, 2 replies; 4+ messages in thread
From: Nathan Chancellor @ 2022-10-25 17:34 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Gautam Menghani, Nick Desaulniers, Tom Rix, linux-mm,
	linux-kernel, llvm, patches, Nathan Chancellor,
	kernel test robot

Clang warns (trimmed for brevity):

  mm/khugepaged.c:1729:7: warning: variable 'index' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
  mm/khugepaged.c:1716:6: warning: variable 'index' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
  mm/khugepaged.c:1729:7: warning: variable 'nr' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
  mm/khugepaged.c:1716:6: warning: variable 'nr' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]

There are two goto statements that will use index and nr before they
have been properly initialized. Zero initialize them so that they can be
safely used by the tracepoint at the end of the function.

Fixes: eae5270d3322 ("mm/khugepaged: add tracepoint to collapse_file()")
Link: https://github.com/ClangBuiltLinux/linux/issues/1749
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 mm/khugepaged.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 977c0ff82c46..789db2f3fc06 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -1702,12 +1702,12 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
 {
 	struct address_space *mapping = file->f_mapping;
 	struct page *hpage;
-	pgoff_t index, end = start + HPAGE_PMD_NR;
+	pgoff_t index = 0, end = start + HPAGE_PMD_NR;
 	LIST_HEAD(pagelist);
 	XA_STATE_ORDER(xas, &mapping->i_pages, start, HPAGE_PMD_ORDER);
 	int nr_none = 0, result = SCAN_SUCCEED;
 	bool is_shmem = shmem_file(file);
-	int nr;
+	int nr = 0;
 
 	VM_BUG_ON(!IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && !is_shmem);
 	VM_BUG_ON(start & (HPAGE_PMD_NR - 1));

base-commit: ec24a700584c4df869282bcd92b6d88329afe395
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-10-26 16:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-25 17:34 [PATCH] mm/khugepaged: Initialize index and nr in collapse_file() Nathan Chancellor
2022-10-25 20:23 ` Zach O'Keefe
2022-10-26  1:48 ` Andrew Morton
2022-10-26 16:39   ` Nathan Chancellor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).