Skip to content

Commit 153ad56

Browse files
nathanchanceakpm00
authored andcommitted
mm/ksm: fix -Wsometimes-uninitialized from clang-21 in advisor_mode_show()
After a recent change in clang to expose uninitialized warnings from const variables [1], there is a false positive warning from the if statement in advisor_mode_show(). mm/ksm.c:3687:11: error: variable 'output' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] 3687 | else if (ksm_advisor == KSM_ADVISOR_SCAN_TIME) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ mm/ksm.c:3690:33: note: uninitialized use occurs here 3690 | return sysfs_emit(buf, "%s\n", output); | ^~~~~~ Rewrite the if statement to implicitly make KSM_ADVISOR_NONE the else branch so that it is obvious to the compiler that ksm_advisor can only be KSM_ADVISOR_NONE or KSM_ADVISOR_SCAN_TIME due to the assignments in advisor_mode_store(). Link: https://lkml.kernel.org/r/20250715-ksm-fix-clang-21-uninit-warning-v1-1-f443feb4bfc4@kernel.org Fixes: 66790e9 ("mm/ksm: add sysfs knobs for advisor") Signed-off-by: Nathan Chancellor <[email protected]> Closes: ClangBuiltLinux#2100 Link: llvm/llvm-project@2464313 [1] Acked-by: David Hildenbrand <[email protected]> Cc: Chengming Zhou <[email protected]> Cc: Stefan Roesch <[email protected]> Cc: xu xin <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent d367a17 commit 153ad56

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

mm/ksm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3669,10 +3669,10 @@ static ssize_t advisor_mode_show(struct kobject *kobj,
36693669
{
36703670
const char *output;
36713671

3672-
if (ksm_advisor == KSM_ADVISOR_NONE)
3673-
output = "[none] scan-time";
3674-
else if (ksm_advisor == KSM_ADVISOR_SCAN_TIME)
3672+
if (ksm_advisor == KSM_ADVISOR_SCAN_TIME)
36753673
output = "none [scan-time]";
3674+
else
3675+
output = "[none] scan-time";
36763676

36773677
return sysfs_emit(buf, "%s\n", output);
36783678
}

0 commit comments

Comments
 (0)