lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251203214958.GC3060476@ax162>
Date: Wed, 3 Dec 2025 14:49:58 -0700
From: Nathan Chancellor <nathan@...nel.org>
To: Krzysztof Kozlowski <krzysztof.kozlowski@....qualcomm.com>
Cc: Liam Girdwood <lgirdwood@...il.com>, Mark Brown <broonie@...nel.org>,
	Jaroslav Kysela <perex@...ex.cz>, Takashi Iwai <tiwai@...e.com>,
	Nick Desaulniers <nick.desaulniers+lkml@...il.com>,
	Bill Wendling <morbo@...gle.com>,
	Justin Stitt <justinstitt@...gle.com>, linux-sound@...r.kernel.org,
	linux-kernel@...r.kernel.org, llvm@...ts.linux.dev
Subject: Re: [PATCH] ASoC: codecs: nau8325: Silence uninitialized variables
 warnings

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ