[PATCH 2/4] ASoC: SOF: control: reject invalid switch values
From: Arnav Kapoor
Date: Tue Nov 17 2026 - 06:00:19 EST
snd_sof_switch_put() passes the values from user space to the IPC
switch_put() op unchecked, and the IPC3 and IPC4 ops store them as they
are and send them to the DSP. Writing 2 to a switch such as
"Dmic0 Capture Switch" succeeds and reads back 2, and writing -1 reads
back 4294967295, neither of which is a valid boolean value. The ALSA
mixer-test selftest reports this as a write_invalid failure.
Reject values other than 0 and 1, using the same range check as the
volume controls.
Fixes: c3078f539704 ("ASoC: SOF: Add Sound Open Firmware KControl support")
Signed-off-by: Arnav Kapoor <kapoorarnav43@xxxxxxxxx>
---
sound/soc/sof/control.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/sound/soc/sof/control.c b/sound/soc/sof/control.c
index 02cf59bf1f95..a36c4c1d4505 100644
--- a/sound/soc/sof/control.c
+++ b/sound/soc/sof/control.c
@@ -109,6 +109,9 @@ int snd_sof_switch_put(struct snd_kcontrol *kcontrol,
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
+ if (!snd_sof_values_in_range(scontrol, ucontrol))
+ return -EINVAL;
+
if (tplg_ops && tplg_ops->control && tplg_ops->control->switch_put)
return tplg_ops->control->switch_put(scontrol, ucontrol);
--
2.53.0