From: Andrew Morton <akpm@linux-foundation.org>
To: Nathan Chancellor <nathan@kernel.org>
Cc: David Hildenbrand <david@redhat.com>,
Xu Xin <xu.xin16@zte.com.cn>,
Chengming Zhou <chengming.zhou@linux.dev>,
Stefan Roesch <shr@devkernel.io>,
linux-mm@kvack.org, llvm@lists.linux.dev, stable@vger.kernel.org
Subject: Re: [PATCH] mm/ksm: Fix -Wsometimes-uninitialized from clang-21 in advisor_mode_show()
Date: Tue, 15 Jul 2025 14:49:26 -0700 [thread overview]
Message-ID: <20250715144926.90546c48efc5f288cfde319e@linux-foundation.org> (raw)
In-Reply-To: <20250715-ksm-fix-clang-21-uninit-warning-v1-1-f443feb4bfc4@kernel.org>
On Tue, 15 Jul 2025 12:56:16 -0700 Nathan Chancellor <nathan@kernel.org> wrote:
> After a recent change in clang to expose uninitialized warnings from
> const variables [1], there is a warning from the if statement in
> advisor_mode_show().
I'll change this to "a false positive warning".
> 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().
>
> --- a/mm/ksm.c
> +++ b/mm/ksm.c
> @@ -3682,10 +3682,10 @@ static ssize_t advisor_mode_show(struct kobject *kobj,
> {
> const char *output;
>
> - if (ksm_advisor == KSM_ADVISOR_NONE)
> - output = "[none] scan-time";
> - else if (ksm_advisor == KSM_ADVISOR_SCAN_TIME)
> + if (ksm_advisor == KSM_ADVISOR_SCAN_TIME)
> output = "none [scan-time]";
> + else
> + output = "[none] scan-time";
>
> return sysfs_emit(buf, "%s\n", output);
> }
Ho hum OK, but the code did deteriorate a bit.
static ssize_t advisor_mode_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
const char *output;
if (ksm_advisor == KSM_ADVISOR_SCAN_TIME)
output = "none [scan-time]";
else
output = "[none] scan-time";
return sysfs_emit(buf, "%s\n", output);
}
Inconsistent with the other code which looks at this enum. Previously
the code explicitly recognized that there are only two modes and that
became implicit.
Oh well, no big deal and we don't want clang builds erroring out like
this.
next parent reply other threads:[~2025-07-15 21:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20250715-ksm-fix-clang-21-uninit-warning-v1-1-f443feb4bfc4@kernel.org>
2025-07-15 21:49 ` Andrew Morton [this message]
2025-07-15 22:10 ` David Hildenbrand
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=20250715144926.90546c48efc5f288cfde319e@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=david@redhat.com \
--cc=linux-mm@kvack.org \
--cc=llvm@lists.linux.dev \
--cc=nathan@kernel.org \
--cc=shr@devkernel.io \
--cc=stable@vger.kernel.org \
--cc=xu.xin16@zte.com.cn \
/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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox