mm/khugepaged: Initialize index and nr in collapse_file()
Subsystems (2)
PATCH 1/1 mm/khugepaged: Initialize index and nr in collapse_file()
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.
--- mm/khugepaged.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/khugepaged.c +2 -2
@@ -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
Signature · 1 line
2.38.1
Andrew Morton
maintainerQuoted 10 lines · On Tue, 25 Oct 2022 10:34:07 -0700 Nathan Chancellor <[email protected]> wrote:
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.
Thanks. I've actually dropped the offending patch - I'd like a resend which includes a fix such as this and a good reason for making the change.
Quoted 9 lines · Andrew Morton
Quoted 7 lines · On Tue, 25 Oct 2022 10:34:07 -0700 Nathan Chancellor <[email protected]> wrote:
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]
Quoted 7 lines
Quoted 3 lines
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.
Thanks. I've actually dropped the offending patch - I'd like a resend which includes a fix such as this and a good reason for making the change.
That certainly seems like a reasonable request. Thanks for letting me know!
Cheers,
Nathan