public inbox for llvm@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH] ASoC: codecs: nau8325: Silence uninitialized variables warnings
@ 2025-12-03 14:06 Krzysztof Kozlowski
  2025-12-03 16:50 ` Mark Brown
  2025-12-03 21:49 ` Nathan Chancellor
  0 siblings, 2 replies; 3+ messages in thread
From: Krzysztof Kozlowski @ 2025-12-03 14:06 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	linux-sound, linux-kernel, llvm
  Cc: Krzysztof Kozlowski

clang W=1 builds warn:

  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
initializing them upfront makes the code more obvious and easier, plus
it silences the warning.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
 sound/soc/codecs/nau8325.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/soc/codecs/nau8325.c b/sound/soc/codecs/nau8325.c
index 3bfdb448f8bd..e651263a9812 100644
--- a/sound/soc/codecs/nau8325.c
+++ b/sound/soc/codecs/nau8325.c
@@ -386,7 +386,8 @@ 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, ratio;
+	int mclk_max = 0, ratio_sel = 0, n2_max = 0;
 
 	if (!nau8325->mclk || !nau8325->fs)
 		goto proc_err;
@@ -408,7 +409,6 @@ static int nau8325_clksrc_choose(struct nau8325 *nau8325,
 	}
 
 	/* Get MCLK_SRC through 1/N, Multiplier, and then 1/N2. */
-	mclk_max = 0;
 	for (i = 0; i < ARRAY_SIZE(mclk_n1_div); i++) {
 		for (j = 0; j < ARRAY_SIZE(mclk_n3_mult); j++) {
 			mclk = nau8325->mclk << mclk_n3_mult[j].param;
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ASoC: codecs: nau8325: Silence uninitialized variables warnings
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2025-12-03 16:50 UTC (permalink / raw)
  To: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, linux-sound,
	linux-kernel, llvm, Krzysztof Kozlowski

On Wed, 03 Dec 2025 15:06:12 +0100, Krzysztof Kozlowski wrote:
> clang W=1 builds warn:
> 
>   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
> initializing them upfront makes the code more obvious and easier, plus
> it silences the warning.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: codecs: nau8325: Silence uninitialized variables warnings
      commit: 2c7e5e17c05f1d5e10e63e1baff2b362cd08dcd6

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ASoC: codecs: nau8325: Silence uninitialized variables warnings
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Nathan Chancellor @ 2025-12-03 21:49 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Nick Desaulniers, Bill Wendling, Justin Stitt, linux-sound,
	linux-kernel, llvm

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-12-03 21:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox