From: David Hildenbrand <david@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Nathan Chancellor <nathan@kernel.org>
Cc: 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: Wed, 16 Jul 2025 00:10:28 +0200 [thread overview]
Message-ID: <ff2b8113-4fca-4de6-8703-f3e50a27bb68@redhat.com> (raw)
In-Reply-To: <20250715144926.90546c48efc5f288cfde319e@linux-foundation.org>
On 15.07.25 23:49, Andrew Morton wrote:
> 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.
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
prev parent reply other threads:[~2025-07-15 22:10 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
2025-07-15 22:10 ` David Hildenbrand [this message]
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=ff2b8113-4fca-4de6-8703-f3e50a27bb68@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--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