mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: Oder Chiou <oder_chiou@realtek.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	 Mark Brown <broonie@kernel.org>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>
Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
	 llvm@lists.linux.dev, Elkin Cruz <elkin@google.com>,
	Ian Rogers <irogers@google.com>
Subject: [PATCH] ASoC: rt1320-sdw: Reject unknown dev_id in FU Capture Volume handlers
Date: Thu, 19 Nov 2026 09:06:56 -0800	[thread overview]
Message-ID: <20261119170656.1522183-1-irogers@google.com> (raw)

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


                 reply	other threads:[~2026-11-19 17:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119170656.1522183-1-irogers@google.com \
    --to=irogers@google.com \
    --cc=broonie@kernel.org \
    --cc=elkin@google.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=oder_chiou@realtek.com \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®