Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ASoC: rt1320-sdw: Reject unknown dev_id in FU Capture Volume handlers
@ 2026-11-19 17:06 Ian Rogers
  2026-11-19 17:23 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Ian Rogers @ 2026-11-19 17:06 UTC (permalink / raw)
  To: Oder Chiou, Liam Girdwood, Mark Brown, Jaroslav Kysela,
	Takashi Iwai
  Cc: linux-sound, linux-kernel, llvm, Elkin Cruz, Ian Rogers

rt1320_sdw_init() registers the ASoC component and its "FU Capture Volume"
control before SoundWire peripheral enumeration populates rt1320->dev_id
(which starts at 0). Unlike rt1320_set_fu_capture_ctl(), the
switch (rt1320->dev_id) blocks in rt1320_set_gain_get() and
rt1320_set_gain_put() omit a default case. Reading "FU Capture Volume"
before enumeration completes (or with an unrecognized dev_id) leaves
'regvalue' uninitialized on the stack and returns a value derived from it
directly to userspace; writing the control similarly reads uninitialized
'regvalue', 'err', and 'reg_base'.

Return -EINVAL in the default branch of all three switch statements,
matching rt1320_set_fu_capture_ctl().

Found via an x86_64 LLVM=1 (Clang 21.1.8) allyesconfig audit with
-Wconditional-uninitialized enabled; fix and changelog drafted with an AI
coding assistant. Build-tested under LLVM=1 W=1 (-Werror) and
-Wconditional-uninitialized; not tested on Realtek RT1320/RT1321 hardware.

Fixes: 7bf9e646af9a ("ASoC: rt1321: Add RT1321 amplifier support")
Signed-off-by: Ian Rogers <irogers@google.com>
---
 sound/soc/codecs/rt1320-sdw.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/sound/soc/codecs/rt1320-sdw.c b/sound/soc/codecs/rt1320-sdw.c
index 20288ea7a2ff..19f7aafc6f2d 100644
--- a/sound/soc/codecs/rt1320-sdw.c
+++ b/sound/soc/codecs/rt1320-sdw.c
@@ -2672,6 +2672,8 @@ static int rt1320_set_gain_put(struct snd_kcontrol *kcontrol,
 			reg_base = SDW_SDCA_CTL(FUNC_NUM_MIC, RT1320_SDCA_ENT_FU113, RT1320_SDCA_CTL_FU_VOLUME, CH_01);
 			regmap_read(rt1320->mbq_regmap, reg_base + i, &regvalue[i]);
 			break;
+		default:
+			return -EINVAL;
 		}
 
 		gain_val[i] = ucontrol->value.integer.value[i];
@@ -2702,6 +2704,8 @@ static int rt1320_set_gain_put(struct snd_kcontrol *kcontrol,
 			reg_base = SDW_SDCA_CTL(FUNC_NUM_MIC, RT1320_SDCA_ENT_FU113, RT1320_SDCA_CTL_FU_VOLUME, CH_01);
 			err = regmap_write(rt1320->mbq_regmap, reg_base + i, gain_val[i]);
 			break;
+		default:
+			return -EINVAL;
 		}
 
 		if (err < 0)
@@ -2760,6 +2764,8 @@ static int rt1320_set_gain_get(struct snd_kcontrol *kcontrol,
 			reg_base = SDW_SDCA_CTL(FUNC_NUM_MIC, RT1320_SDCA_ENT_FU113, RT1320_SDCA_CTL_FU_VOLUME, CH_01);
 			regmap_read(rt1320->mbq_regmap, reg_base + i, &regvalue);
 			break;
+		default:
+			return -EINVAL;
 		}
 
 		ctl = p->max - (((0x1e00 - regvalue) & 0xffff) / interval_offset);
-- 
2.56.1.708.g77570a6a1d-goog


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

* Re: [PATCH] ASoC: rt1320-sdw: Reject unknown dev_id in FU Capture Volume handlers
  2026-11-19 17:06 [PATCH] ASoC: rt1320-sdw: Reject unknown dev_id in FU Capture Volume handlers Ian Rogers
@ 2026-11-19 17:23 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-19 17:23 UTC (permalink / raw)
  To: Ian Rogers; +Cc: linux-sound

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] ASoC: codecs: unsigned cast bypasses bounds check in
  set_gain_put() [1]
--

commit 6b4eb08972e9d693f4ba90820d49635baaaa320b
Author: Ian Rogers <irogers@google.com>

ASoC: rt1320-sdw: Reject unknown dev_id in FU Capture Volume handlers

This commit adds default branches returning -EINVAL to the dev_id switch
statements in rt1320_set_gain_put() and rt1320_set_gain_get() to avoid
using uninitialized stack variables when the device ID is not yet
populated or unrecognized.

> diff --git a/sound/soc/codecs/rt1320-sdw.c b/sound/soc/codecs/rt1320-sdw.c
> index 19079212ba6c0..6724012d5c09d 100644
> --- a/sound/soc/codecs/rt1320-sdw.c
> +++ b/sound/soc/codecs/rt1320-sdw.c
> @@ -2829,6 +2829,8 @@ static int rt1320_set_gain_put(struct snd_kcontrol *kcontrol,
>  			reg_base = SDW_SDCA_CTL(FUNC_NUM_MIC, RT1320_SDCA_ENT_FU113, RT1320_SDCA_CTL_FU_VOLUME, CH_01);
>  			regmap_read(rt1320->mbq_regmap, reg_base + i, &regvalue[i]);
>  			break;
> +		default:
> +			return -EINVAL;
>  		}
>  
>  		gain_val[i] = ucontrol->value.integer.value[i];

[Severity: High]
This problem wasn't introduced by this patch, but can a negative
ucontrol->value.integer.value[i] wrap when assigned to the unsigned
gain_val[i] [1]?  A negative value from userspace converts to a
large unsigned integer and gets clamped to p->max by the following
gain_val[i] > p->max check, setting the gain to maximum instead of
rejecting or clamping it to the minimum.

[1] https://sashiko.dev/#/bug/linux-4e6d0e9a-edf1-4f06-b366-c7939979db0e

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119170656.1522183-1-irogers@google.com?part=1

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

end of thread, other threads:[~2026-11-19 17:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 17:06 [PATCH] ASoC: rt1320-sdw: Reject unknown dev_id in FU Capture Volume handlers Ian Rogers
2026-11-19 17:23 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox