ASoC: rt1320-sdw: Reject unknown dev_id in FU Capture Volume handlers
Subsystems (3)
PATCH 1/1 ASoC: rt1320-sdw: Reject unknown dev_id in FU Capture Volume handlers
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.
--- sound/soc/codecs/rt1320-sdw.c | 6 ++++++ 1 file changed, 6 insertions(+)
sound/soc/codecs/rt1320-sdw.c +6 -0
@@ -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, ®value[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, ®value);break ; +default : +return -EINVAL ; } ctl = p->max - (((0x1e00 - regvalue) &0xffff ) / interval_offset);
Signature · 1 line
2.56.1.708.g77570a6a1d-goog
[email protected]
AI reviewThank 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…
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 <[email protected]>
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.
sound/soc/codecs/rt1320-sdw.c static int rt1320_set_gain_put(struct snd_kcontrol *kcontrol, · line 2836
Quoted 13 lines
sound/soc/codecs/rt1320-sdw.c +2
-0@@ -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, ®value[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
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1