All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] ASoC: codecs: lpass-wsa-macro: handle unexpected input
@ 2021-04-30 14:21 ` trix
  0 siblings, 0 replies; 5+ messages in thread
From: trix @ 2021-04-30 14:21 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 switch statement that sets ec_tx.  Add a default
case that returns an error before the array is accessed.

Signed-off-by: Tom Rix <trix@redhat.com>
---
v2:
  - handle the input error, keep switch
---
 sound/soc/codecs/lpass-wsa-macro.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/sound/soc/codecs/lpass-wsa-macro.c b/sound/soc/codecs/lpass-wsa-macro.c
index 1a7fa5492f28..d3ac318fd6b6 100644
--- a/sound/soc/codecs/lpass-wsa-macro.c
+++ b/sound/soc/codecs/lpass-wsa-macro.c
@@ -1727,6 +1727,10 @@ static int wsa_macro_enable_echo(struct snd_soc_dapm_widget *w,
 		val = val & CDC_WSA_RX_MIX_TX1_SEL_MASK;
 		ec_tx = (val >> CDC_WSA_RX_MIX_TX1_SEL_SHFT) - 1;
 		break;
+	default:
+		dev_err(component->dev,	"%s: Invalid shift %u\n",
+			__func__, w->shift);
+		return -EINVAL;
 	}
 
 	if (wsa->ec_hq[ec_tx]) {
-- 
2.26.3


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

* [PATCH v2] ASoC: codecs: lpass-wsa-macro: handle unexpected input
@ 2021-04-30 14:21 ` trix
  0 siblings, 0 replies; 5+ messages in thread
From: trix @ 2021-04-30 14:21 UTC (permalink / raw)
  To: srinivas.kandagatla, bgoswami, lgirdwood, broonie, perex, tiwai
  Cc: Tom Rix, alsa-devel, linux-kernel

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 switch statement that sets ec_tx.  Add a default
case that returns an error before the array is accessed.

Signed-off-by: Tom Rix <trix@redhat.com>
---
v2:
  - handle the input error, keep switch
---
 sound/soc/codecs/lpass-wsa-macro.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/sound/soc/codecs/lpass-wsa-macro.c b/sound/soc/codecs/lpass-wsa-macro.c
index 1a7fa5492f28..d3ac318fd6b6 100644
--- a/sound/soc/codecs/lpass-wsa-macro.c
+++ b/sound/soc/codecs/lpass-wsa-macro.c
@@ -1727,6 +1727,10 @@ static int wsa_macro_enable_echo(struct snd_soc_dapm_widget *w,
 		val = val & CDC_WSA_RX_MIX_TX1_SEL_MASK;
 		ec_tx = (val >> CDC_WSA_RX_MIX_TX1_SEL_SHFT) - 1;
 		break;
+	default:
+		dev_err(component->dev,	"%s: Invalid shift %u\n",
+			__func__, w->shift);
+		return -EINVAL;
 	}
 
 	if (wsa->ec_hq[ec_tx]) {
-- 
2.26.3


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

* Re: [PATCH v2] ASoC: codecs: lpass-wsa-macro: handle unexpected input
  2021-04-30 14:21 ` trix
  (?)
@ 2021-04-30 16:36 ` Srinivas Kandagatla
  -1 siblings, 0 replies; 5+ messages in thread
From: Srinivas Kandagatla @ 2021-04-30 16:36 UTC (permalink / raw)
  To: trix, bgoswami, lgirdwood, broonie, perex, tiwai; +Cc: alsa-devel, linux-kernel

Thanks Tom for fixing this.

On 30/04/2021 15:21, trix@redhat.com wrote:
> 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 switch statement that sets ec_tx.  Add a default
> case that returns an error before the array is accessed.
> 
> Signed-off-by: Tom Rix <trix@redhat.com>
> ---
> v2:
>    - handle the input error, keep switch
> ---
>   sound/soc/codecs/lpass-wsa-macro.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/sound/soc/codecs/lpass-wsa-macro.c b/sound/soc/codecs/lpass-wsa-macro.c
> index 1a7fa5492f28..d3ac318fd6b6 100644
> --- a/sound/soc/codecs/lpass-wsa-macro.c
> +++ b/sound/soc/codecs/lpass-wsa-macro.c
> @@ -1727,6 +1727,10 @@ static int wsa_macro_enable_echo(struct snd_soc_dapm_widget *w,
>   		val = val & CDC_WSA_RX_MIX_TX1_SEL_MASK;
>   		ec_tx = (val >> CDC_WSA_RX_MIX_TX1_SEL_SHFT) - 1;
>   		break;
> +	default:
> +		dev_err(component->dev,	"%s: Invalid shift %u\n",
> +			__func__, w->shift);
> +		return -EINVAL;

With the existing code we should never even touch this default path,

However the changes look safe to me,

Reviewed-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>


--srini


>   	}
>   
>   	if (wsa->ec_hq[ec_tx]) {
> 

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

* Re: [PATCH v2] ASoC: codecs: lpass-wsa-macro: handle unexpected input
  2021-04-30 14:21 ` trix
@ 2021-05-11  8:25   ` Mark Brown
  -1 siblings, 0 replies; 5+ messages in thread
From: Mark Brown @ 2021-05-11  8:25 UTC (permalink / raw)
  To: lgirdwood, srinivas.kandagatla, perex, bgoswami, trix, tiwai
  Cc: Mark Brown, linux-kernel, alsa-devel

On Fri, 30 Apr 2021 07:21:17 -0700, trix@redhat.com wrote:
> 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 switch statement that sets ec_tx.  Add a default
> case that returns an error before the array is accessed.

Applied to

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

Thanks!

[1/1] ASoC: codecs: lpass-wsa-macro: handle unexpected input
      commit: 58f01c7fc81baced84f237554d56847e17b5d730

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] 5+ messages in thread

* Re: [PATCH v2] ASoC: codecs: lpass-wsa-macro: handle unexpected input
@ 2021-05-11  8:25   ` Mark Brown
  0 siblings, 0 replies; 5+ messages in thread
From: Mark Brown @ 2021-05-11  8:25 UTC (permalink / raw)
  To: lgirdwood, srinivas.kandagatla, perex, bgoswami, trix, tiwai
  Cc: alsa-devel, Mark Brown, linux-kernel

On Fri, 30 Apr 2021 07:21:17 -0700, trix@redhat.com wrote:
> 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 switch statement that sets ec_tx.  Add a default
> case that returns an error before the array is accessed.

Applied to

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

Thanks!

[1/1] ASoC: codecs: lpass-wsa-macro: handle unexpected input
      commit: 58f01c7fc81baced84f237554d56847e17b5d730

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] 5+ messages in thread

end of thread, other threads:[~2021-05-11  8:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-30 14:21 [PATCH v2] ASoC: codecs: lpass-wsa-macro: handle unexpected input trix
2021-04-30 14:21 ` trix
2021-04-30 16:36 ` Srinivas Kandagatla
2021-05-11  8:25 ` Mark Brown
2021-05-11  8:25   ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.