linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: codecs: lpass-wsa-macro: make sure array index is set
@ 2021-04-29 17:36 trix
  2021-04-30 11:23 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: trix @ 2021-04-29 17:36 UTC (permalink / raw)
  To: srinivas.kandagatla, bgoswami, lgirdwood, broonie, perex, tiwai
  Cc: alsa-devel, linux-kernel, Tom Rix

From: Tom Rix <trix@redhat.com>

Static analysis reports this problem

lpass-wsa-macro.c:1732:6: warning: Array subscript is undefined
        if (wsa->ec_hq[ec_tx]) {
            ^~~~~~~~~~~~~~~~~

The happens because 'ec_tx' is never initialized and there is
no default in the switch statement that sets ec_tx.  Because there
are only two cases for the switch, convert it to an if-else.

Signed-off-by: Tom Rix <trix@redhat.com>
---
 sound/soc/codecs/lpass-wsa-macro.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/sound/soc/codecs/lpass-wsa-macro.c b/sound/soc/codecs/lpass-wsa-macro.c
index 1a7fa5492f28..c11ae72f2148 100644
--- a/sound/soc/codecs/lpass-wsa-macro.c
+++ b/sound/soc/codecs/lpass-wsa-macro.c
@@ -1718,15 +1718,13 @@ static int wsa_macro_enable_echo(struct snd_soc_dapm_widget *w,
 
 	val = snd_soc_component_read(component, CDC_WSA_RX_INP_MUX_RX_MIX_CFG0);
 
-	switch (w->shift) {
-	case WSA_MACRO_EC0_MUX:
+	if (w->shift == WSA_MACRO_EC0_MUX) {
 		val = val & CDC_WSA_RX_MIX_TX0_SEL_MASK;
 		ec_tx = val - 1;
-		break;
-	case WSA_MACRO_EC1_MUX:
+	} else {
+		/* WSA_MACRO_EC1_MUX */
 		val = val & CDC_WSA_RX_MIX_TX1_SEL_MASK;
 		ec_tx = (val >> CDC_WSA_RX_MIX_TX1_SEL_SHFT) - 1;
-		break;
 	}
 
 	if (wsa->ec_hq[ec_tx]) {
-- 
2.26.3


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

* Re: [PATCH] ASoC: codecs: lpass-wsa-macro: make sure array index is set
  2021-04-29 17:36 [PATCH] ASoC: codecs: lpass-wsa-macro: make sure array index is set trix
@ 2021-04-30 11:23 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2021-04-30 11:23 UTC (permalink / raw)
  To: trix
  Cc: srinivas.kandagatla, bgoswami, lgirdwood, perex, tiwai,
	alsa-devel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 358 bytes --]

On Thu, Apr 29, 2021 at 10:36:42AM -0700, trix@redhat.com wrote:

> The happens because 'ec_tx' is never initialized and there is
> no default in the switch statement that sets ec_tx.  Because there
> are only two cases for the switch, convert it to an if-else.

Add a default case that errors, that way if someone adds a new option
things are less painful.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2021-04-30 11:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-29 17:36 [PATCH] ASoC: codecs: lpass-wsa-macro: make sure array index is set trix
2021-04-30 11:23 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).