From: Nathan Chancellor <nathan@kernel.org>
To: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Cc: Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
Takashi Iwai <tiwai@suse.com>,
Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev
Subject: Re: [PATCH] ASoC: codecs: nau8325: Silence uninitialized variables warnings
Date: Wed, 3 Dec 2025 14:49:58 -0700 [thread overview]
Message-ID: <20251203214958.GC3060476@ax162> (raw)
In-Reply-To: <20251203140611.87191-2-krzysztof.kozlowski@oss.qualcomm.com>
Hi Krzysztof,
On Wed, Dec 03, 2025 at 03:06:12PM +0100, Krzysztof Kozlowski wrote:
> clang W=1 builds warn:
For the record, W=1 is irrelevant here, this warning occurs in a default
build as well. I only mention that because I think some maintainers
mentally downplay W=1 patches (I know Mark already picked this up).
-Wuninitialized and -Wsometimes-uninitialized should always appear,
regardless of W=1.
> nau8325.c:430:13: error: variable 'n2_max' is uninitialized when used here [-Werror,-Wuninitialized]
>
> which are false positive, because the variables will be always
> initialized when used (guarded by mclk_max!=0 check). However
Right, which I pointed out on another report:
https://lore.kernel.org/all/20251201191052.GA2727778@ax162/
> initializing them upfront makes the code more obvious and easier, plus
> it silences the warning.
I get silencing the warning to avoid breaking the build but I think the
warning is flagging that this code is dodgy.
If we remove the known dead code as the solution to the original
problem:
diff --git a/sound/soc/codecs/nau8325.c b/sound/soc/codecs/nau8325.c
index 3bfdb448f8bd..e060a8950940 100644
--- a/sound/soc/codecs/nau8325.c
+++ b/sound/soc/codecs/nau8325.c
@@ -426,11 +426,6 @@ static int nau8325_clksrc_choose(struct nau8325 *nau8325,
}
}
}
- if (mclk_max) {
- *n2_sel = n2_max;
- ratio = ratio_sel;
- goto proc_done;
- }
proc_err:
dev_dbg(nau8325->dev, "The MCLK %d is invalid. It can't get MCLK_SRC of 256/400/500 FS (%d)",
Then we get the following warnings with W=1:
sound/soc/codecs/nau8325.c:389:35: error: variable 'ratio_sel' set but not used [-Werror,-Wunused-but-set-variable]
389 | int i, j, mclk, mclk_max, ratio, ratio_sel, n2_max;
| ^
sound/soc/codecs/nau8325.c:389:46: error: variable 'n2_max' set but not used [-Werror,-Wunused-but-set-variable]
389 | int i, j, mclk, mclk_max, ratio, ratio_sel, n2_max;
| ^
So then we remove these variables:
diff --git a/sound/soc/codecs/nau8325.c b/sound/soc/codecs/nau8325.c
index e060a8950940..86725912a014 100644
--- a/sound/soc/codecs/nau8325.c
+++ b/sound/soc/codecs/nau8325.c
@@ -386,7 +386,7 @@ static int nau8325_clksrc_choose(struct nau8325 *nau8325,
const struct nau8325_srate_attr **srate_table,
int *n1_sel, int *mult_sel, int *n2_sel)
{
- int i, j, mclk, mclk_max, ratio, ratio_sel, n2_max;
+ int i, j, mclk, mclk_max, ratio;
if (!nau8325->mclk || !nau8325->fs)
goto proc_err;
@@ -418,10 +418,8 @@ static int nau8325_clksrc_choose(struct nau8325 *nau8325,
if (ratio != NAU8325_MCLK_FS_RATIO_NUM &&
(mclk_max < mclk || i > *n1_sel)) {
mclk_max = mclk;
- n2_max = *n2_sel;
*n1_sel = i;
*mult_sel = j;
- ratio_sel = ratio;
goto proc_done;
}
}
Then there are no warnings but was it intentional that these variables
were unused? I was hoping the original author would be able to answer
that. At the very least, it seems better to remove the known dead code
than leave it around for the compiler to clean up.
Cheers,
Nathan
prev parent reply other threads:[~2025-12-03 21:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-03 14:06 [PATCH] ASoC: codecs: nau8325: Silence uninitialized variables warnings Krzysztof Kozlowski
2025-12-03 16:50 ` Mark Brown
2025-12-03 21:49 ` Nathan Chancellor [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=20251203214958.GC3060476@ax162 \
--to=nathan@kernel.org \
--cc=broonie@kernel.org \
--cc=justinstitt@google.com \
--cc=krzysztof.kozlowski@oss.qualcomm.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=morbo@google.com \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=perex@perex.cz \
--cc=tiwai@suse.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