From: Matt Flax <flatmax@flatmax.com>
To: Nathan Chancellor <nathan@kernel.org>
Cc: Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Tom Rix <trix@redhat.com>,
alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev, patches@lists.linux.dev,
kernel test robot <lkp@intel.com>,
"Sudip Mukherjee (Codethink)" <sudipm.mukherjee@gmail.com>
Subject: Re: [PATCH] ASoC: codes: src4xxx: Avoid clang -Wsometimes-uninitialized in src4xxx_hw_params()
Date: Tue, 23 Aug 2022 08:35:26 +1000 [thread overview]
Message-ID: <99a54f9c-519e-1ccb-8ceb-391a0aeb359d@flatmax.com> (raw)
In-Reply-To: <YwQEDyk17Q06mIVR@dev-arch.thelio-3990X>
That solution looks good.
Matt
On 23/8/22 08:32, Nathan Chancellor wrote:
> Hi Matt,
>
> On Tue, Aug 23, 2022 at 08:00:07AM +1000, Matt Flax wrote:
>> Hi Nathan,
>>
>> On 23/8/22 04:31, Nathan Chancellor wrote:
>>> Clang warns:
>>>
>>> sound/soc/codecs/src4xxx.c:280:3: error: variable 'd' is used uninitialized whenever switch default is taken [-Werror,-Wsometimes-uninitialized]
>>> default:
>>> ^~~~~~~
>>> sound/soc/codecs/src4xxx.c:298:59: note: uninitialized use occurs here
>>> ret = regmap_write(src4xxx->regmap, SRC4XXX_RCV_PLL_11, d);
>>> ^
>>> sound/soc/codecs/src4xxx.c:223:20: note: initialize the variable 'd' to silence this warning
>>> int val, pj, jd, d;
>>> ^
>>> = 0
>>
>> If you really want to get rid of these warnings, you can use this default
>> for the variables :
>>
>> pj = 0x0;
>> jd=0xff;
>>
>> d = 0xff;
>>
>> It doesn't really make sense why we would choose to initialise these
>> variables, but if you want to silence the preprocessor, then perhaps those
>> values. Put a message that defaults are not known nor specified in the data
>> sheet and these values are chosen to be unlikely matches of real world
>> values - which ensures regmap updates later from an initial unknown chip
>> state after refresh.
> Okay, I could do something like this?
>
> diff --git a/sound/soc/codecs/src4xxx.c b/sound/soc/codecs/src4xxx.c
> index a8f143057b41..db4e280dd055 100644
> --- a/sound/soc/codecs/src4xxx.c
> +++ b/sound/soc/codecs/src4xxx.c
> @@ -280,9 +280,14 @@ static int src4xxx_hw_params(struct snd_pcm_substream *substream,
> default:
> /* don't error out here,
> * other parts of the chip are still functional
> + * Dummy initialize variables to avoid
> + * -Wsometimes-uninitialized from clang.
> */
> dev_info(component->dev,
> - "Couldn't set the RCV PLL as this master clock rate is unknown\n");
> + "Couldn't set the RCV PLL as this master clock rate is unknown. Chosen regmap values may not match real world values.\n");
> + pj = 0x0;
> + jd = 0xff;
> + d = 0xff;
> break;
> }
> ret = regmap_write(src4xxx->regmap, SRC4XXX_RCV_PLL_0F, pj);
>
> These warnings need to be eliminated because Linus requires a clean
> build as much as possible [1] [2], which has been codified by
> CONFIG_WERROR, which is enabled by default with allmodconfig. As a
> result, clang allmodconfig builds are broken [3], which you might have
> already seen. If there is another way this could be written without
> potentially uninitialized variables, I am open to it.
>
> [1]: https://lore.kernel.org/CAHk-=wg-mH-_GYpkhz_psjBWG6ZcjKnPo83fg7YMj_by+-LRTQ@mail.gmail.com/
> [2]: https://lore.kernel.org/CAHk-=wi4wyvuXs0SUq-2x=XHxWmJ6jVKRD-WpE0kWgWiqVJNbg@mail.gmail.com/
> [3]: https://lore.kernel.org/YwNMUlAmu%2FqCjuva@debian/
>
>> All a bit messy really.
> Indeed :/
>
>>> According to the comment in the default case, other parts of the chip
>>> are still functional without these values so just return 0 in the
>>> default case to avoid using these variables uninitialized.
>>>
>>> Link: https://github.com/ClangBuiltLinux/linux/issues/1691
>>> Reported-by: kernel test robot <lkp@intel.com>
>>> Reported-by: "Sudip Mukherjee (Codethink)" <sudipm.mukherjee@gmail.com>
>>> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
>>> ---
>>> sound/soc/codecs/src4xxx.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/sound/soc/codecs/src4xxx.c b/sound/soc/codecs/src4xxx.c
>>> index a8f143057b41..cf45caa4bf7f 100644
>>> --- a/sound/soc/codecs/src4xxx.c
>>> +++ b/sound/soc/codecs/src4xxx.c
>>> @@ -283,7 +283,7 @@ static int src4xxx_hw_params(struct snd_pcm_substream *substream,
>>> */
>>> dev_info(component->dev,
>>> "Couldn't set the RCV PLL as this master clock rate is unknown\n");
>>> - break;
>>> + return 0;
>>
>> Don't return here, the rest of the chip is still functional and probably in
>> use. Print the dev_info and continue.
> I'll send a v2 tomorrow morning (for me at least) if there are no other
> comments.
>
> Cheers,
> Nathan
prev parent reply other threads:[~2022-08-22 22:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-22 18:31 Nathan Chancellor
2022-08-22 22:00 ` Matt Flax
2022-08-22 22:32 ` Nathan Chancellor
2022-08-22 22:35 ` Matt Flax [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=99a54f9c-519e-1ccb-8ceb-391a0aeb359d@flatmax.com \
--to=flatmax@flatmax.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=llvm@lists.linux.dev \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=patches@lists.linux.dev \
--cc=sudipm.mukherjee@gmail.com \
--cc=trix@redhat.com \
/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
all inboxes | Powered by JetHome®