* [PATCH 0/4] ASoC: SOF: control: fix volume, switch and enum value handling
@ 2026-11-17 10:59 Arnav Kapoor
2026-11-17 10:59 ` [PATCH 1/4] ASoC: SOF: control: reject out-of-range volume values Arnav Kapoor
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Arnav Kapoor @ 2026-11-17 10:59 UTC (permalink / raw)
To: Mark Brown, Liam Girdwood, Peter Ujfalusi, Bard Liao, Daniel Baluta
Cc: Ranjani Sridharan, Kai Vehmanen, Pierre-Louis Bossart,
Jaroslav Kysela, Takashi Iwai, sound-open-firmware, linux-sound,
linux-kernel, Arnav Kapoor
The ALSA mixer-test selftest fails on the SOF controls of a Lenovo V14
G2 ITL (Tiger Lake, sof-hda-generic-2ch.tplg). The HDA codec controls on
the same card pass. These patches fix what it found, plus one case it
doesn't catch:
1: a negative volume sets the control to its maximum, because
mixer_to_ipc() takes an unsigned int and clamps.
2: a switch accepts and stores values other than 0 and 1.
3: writing back the volume that was just read generates a change
event, because put() compares linear gains while get() reports
table steps, and the 0 dB default is not a table entry.
4: an enum accepts item indexes past its last item (IPC4 topology
only has one, "Dmic0 Capture TDFB angle set enum").
Patches 1, 2 and 4 are in the IPC-independent control.c; patch 3
touches the IPC3 and IPC4 volume_put() ops.
Tested on that laptop (7.0.14 kernel, snd-sof rebuilt with these
patches) with mixer-test:
- IPC3 (sof-tgl.ri, sof-hda-generic-2ch.tplg):
287 pass / 8 fail before, 295 pass / 0 fail after
- IPC4 (sof-ipc4/tgl, sof-ipc4-tplg/sof-hda-generic-2ch.tplg):
287 pass / 12 fail before, 296 pass / 3 fail after
The three remaining IPC4 failures are control names in the topology
(boolean controls named "... switch" instead of "... Switch").
I also wrote out-of-range values to every control with plain alsa-lib
calls (amixer clamps them before they reach the kernel). Before the
series every SOF volume and switch accepted them with IPC3; after it
every SOF volume, switch and enum rejects them with -EINVAL, with both
IPC3 and IPC4. pcm-test results are the same with and without the
patches.
Arnav Kapoor (4):
ASoC: SOF: control: reject out-of-range volume values
ASoC: SOF: control: reject invalid switch values
ASoC: SOF: report volume changes in mixer steps
ASoC: SOF: control: reject out-of-range enum values
sound/soc/sof/control.c | 26 ++++++++++++++++++++++++++
sound/soc/sof/ipc3-control.c | 4 +++-
sound/soc/sof/ipc4-control.c | 4 +++-
3 files changed, 32 insertions(+), 2 deletions(-)
base-commit: 7cd6b1fd8f9c1fcb1da1b761d502649f50b9800f
--
2.53.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/4] ASoC: SOF: control: reject out-of-range volume values
2026-11-17 10:59 [PATCH 0/4] ASoC: SOF: control: fix volume, switch and enum value handling Arnav Kapoor
@ 2026-11-17 10:59 ` Arnav Kapoor
2026-11-17 10:59 ` [PATCH 2/4] ASoC: SOF: control: reject invalid switch values Arnav Kapoor
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Arnav Kapoor @ 2026-11-17 10:59 UTC (permalink / raw)
To: Mark Brown, Liam Girdwood, Peter Ujfalusi, Bard Liao, Daniel Baluta
Cc: Ranjani Sridharan, Kai Vehmanen, Pierre-Louis Bossart,
Jaroslav Kysela, Takashi Iwai, sound-open-firmware, linux-sound,
linux-kernel, Arnav Kapoor
snd_sof_volume_put() passes the values from user space to the IPC
volume_put() op without checking them. The IPC3 and IPC4 ops convert
each value with mixer_to_ipc(), which takes an unsigned int and clamps
anything past the end of the volume table to its last entry. A negative
value therefore sets the volume to the maximum: on a Tiger Lake laptop
with sof-hda-generic-2ch.tplg, writing -1 to "PGA2.0 2 Master Capture
Volume" (0..80, set to 50) succeeds and reads back 80.
Reject values outside 0..max, as the ALSA control API expects, before
calling the op.
Fixes: c3078f539704 ("ASoC: SOF: Add Sound Open Firmware KControl support")
Signed-off-by: Arnav Kapoor <kapoorarnav43@gmail.com>
---
sound/soc/sof/control.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/sound/soc/sof/control.c b/sound/soc/sof/control.c
index 74d997a4f620..02cf59bf1f95 100644
--- a/sound/soc/sof/control.c
+++ b/sound/soc/sof/control.c
@@ -15,6 +15,21 @@
#include "sof-priv.h"
#include "sof-audio.h"
+static bool snd_sof_values_in_range(const struct snd_sof_control *scontrol,
+ const struct snd_ctl_elem_value *ucontrol)
+{
+ unsigned int i;
+
+ for (i = 0; i < scontrol->num_channels; i++) {
+ long value = ucontrol->value.integer.value[i];
+
+ if (value < 0 || value > scontrol->max)
+ return false;
+ }
+
+ return true;
+}
+
int snd_sof_volume_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
@@ -39,6 +54,9 @@ int snd_sof_volume_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->volume_put)
return tplg_ops->control->volume_put(scontrol, ucontrol);
--
2.53.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/4] ASoC: SOF: control: reject invalid switch values
2026-11-17 10:59 [PATCH 0/4] ASoC: SOF: control: fix volume, switch and enum value handling Arnav Kapoor
2026-11-17 10:59 ` [PATCH 1/4] ASoC: SOF: control: reject out-of-range volume values Arnav Kapoor
@ 2026-11-17 10:59 ` Arnav Kapoor
2026-11-17 10:59 ` [PATCH 3/4] ASoC: SOF: report volume changes in mixer steps Arnav Kapoor
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Arnav Kapoor @ 2026-11-17 10:59 UTC (permalink / raw)
To: Mark Brown, Liam Girdwood, Peter Ujfalusi, Bard Liao, Daniel Baluta
Cc: Ranjani Sridharan, Kai Vehmanen, Pierre-Louis Bossart,
Jaroslav Kysela, Takashi Iwai, sound-open-firmware, linux-sound,
linux-kernel, Arnav Kapoor
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@gmail.com>
---
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/4] ASoC: SOF: report volume changes in mixer steps
2026-11-17 10:59 [PATCH 0/4] ASoC: SOF: control: fix volume, switch and enum value handling Arnav Kapoor
2026-11-17 10:59 ` [PATCH 1/4] ASoC: SOF: control: reject out-of-range volume values Arnav Kapoor
2026-11-17 10:59 ` [PATCH 2/4] ASoC: SOF: control: reject invalid switch values Arnav Kapoor
@ 2026-11-17 10:59 ` Arnav Kapoor
2026-11-17 10:59 ` [PATCH 4/4] ASoC: SOF: control: reject out-of-range enum values Arnav Kapoor
2026-11-17 12:24 ` [PATCH 0/4] ASoC: SOF: control: fix volume, switch and enum value handling HyeongJun An
4 siblings, 0 replies; 6+ messages in thread
From: Arnav Kapoor @ 2026-11-17 10:59 UTC (permalink / raw)
To: Mark Brown, Liam Girdwood, Peter Ujfalusi, Bard Liao, Daniel Baluta
Cc: Ranjani Sridharan, Kai Vehmanen, Pierre-Louis Bossart,
Jaroslav Kysela, Takashi Iwai, sound-open-firmware, linux-sound,
linux-kernel, Arnav Kapoor
The IPC3 and IPC4 volume_put() ops decide whether the control changed by
comparing the new linear gain from the volume table with the stored one.
The stored gain does not always come from the table: topology loading
initialises it to 0 dB (VOL_ZERO_DB or SOF_IPC4_VOL_ZERO_DB), and
volume_get() reports that as the first table entry at or above it, which
is usually not exactly 0 dB. Writing back the value that was just read
then changes the stored gain, so put() returns true and user space gets
a change notification although the control value is the same.
On a Tiger Lake laptop with sof-hda-generic-2ch.tplg (IPC3), the ALSA
mixer-test selftest reports this as event_spurious failures for every
PGA playback volume and for "Dmic0 Capture Volume".
Compare in mixer steps instead, using the same ipc_to_mixer() conversion
as volume_get(), so put() returns true only when the value user space
sees changes.
Fixes: 95a32c98055f ("ASoC: SOF: control: return true when kcontrol values change")
Fixes: 955e84fc0b6d ("ASoC: SOF: ipc4-topology: Add control IO ops")
Signed-off-by: Arnav Kapoor <kapoorarnav43@gmail.com>
---
sound/soc/sof/ipc3-control.c | 4 +++-
sound/soc/sof/ipc4-control.c | 4 +++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/sound/soc/sof/ipc3-control.c b/sound/soc/sof/ipc3-control.c
index b1d00a2a860a..b8f4d963e07d 100644
--- a/sound/soc/sof/ipc3-control.c
+++ b/sound/soc/sof/ipc3-control.c
@@ -180,10 +180,12 @@ static bool sof_ipc3_volume_put(struct snd_sof_control *scontrol,
/* update each channel */
for (i = 0; i < channels; i++) {
+ u32 old = ipc_to_mixer(cdata->chanv[i].value,
+ scontrol->volume_table, scontrol->max + 1);
u32 value = mixer_to_ipc(ucontrol->value.integer.value[i],
scontrol->volume_table, scontrol->max + 1);
- change = change || (value != cdata->chanv[i].value);
+ change = change || (ucontrol->value.integer.value[i] != old);
cdata->chanv[i].channel = i;
cdata->chanv[i].value = value;
}
diff --git a/sound/soc/sof/ipc4-control.c b/sound/soc/sof/ipc4-control.c
index e29c8d89284a..8bf300373d22 100644
--- a/sound/soc/sof/ipc4-control.c
+++ b/sound/soc/sof/ipc4-control.c
@@ -153,10 +153,12 @@ static bool sof_ipc4_volume_put(struct snd_sof_control *scontrol,
/* update each channel */
for (i = 0; i < channels; i++) {
+ u32 old = ipc_to_mixer(cdata->chanv[i].value,
+ scontrol->volume_table, scontrol->max + 1);
u32 value = mixer_to_ipc(ucontrol->value.integer.value[i],
scontrol->volume_table, scontrol->max + 1);
- change = change || (value != cdata->chanv[i].value);
+ change = change || (ucontrol->value.integer.value[i] != old);
cdata->chanv[i].channel = i;
cdata->chanv[i].value = value;
}
--
2.53.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 4/4] ASoC: SOF: control: reject out-of-range enum values
2026-11-17 10:59 [PATCH 0/4] ASoC: SOF: control: fix volume, switch and enum value handling Arnav Kapoor
` (2 preceding siblings ...)
2026-11-17 10:59 ` [PATCH 3/4] ASoC: SOF: report volume changes in mixer steps Arnav Kapoor
@ 2026-11-17 10:59 ` Arnav Kapoor
2026-11-17 12:24 ` [PATCH 0/4] ASoC: SOF: control: fix volume, switch and enum value handling HyeongJun An
4 siblings, 0 replies; 6+ messages in thread
From: Arnav Kapoor @ 2026-11-17 10:59 UTC (permalink / raw)
To: Mark Brown, Liam Girdwood, Peter Ujfalusi, Bard Liao, Daniel Baluta
Cc: Ranjani Sridharan, Kai Vehmanen, Pierre-Louis Bossart,
Jaroslav Kysela, Takashi Iwai, sound-open-firmware, linux-sound,
linux-kernel, Arnav Kapoor
snd_sof_enum_put() passes the item indexes from user space to the IPC
enum_put() op unchecked, and the IPC3 and IPC4 ops store them as they
are and send them to the DSP. With the IPC4 sof-hda-generic-2ch.tplg on
a Tiger Lake laptop, "Dmic0 Capture TDFB angle set enum" has 13 items
but accepts 13 and 0xffffffff, and reads them back. The ALSA mixer-test
selftest reports this as a write_invalid failure.
Reject indexes past the last item, as snd_soc_put_enum_double() does.
Fixes: c3078f539704 ("ASoC: SOF: Add Sound Open Firmware KControl support")
Signed-off-by: Arnav Kapoor <kapoorarnav43@gmail.com>
---
sound/soc/sof/control.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/sound/soc/sof/control.c b/sound/soc/sof/control.c
index a36c4c1d4505..aa02376d61e6 100644
--- a/sound/soc/sof/control.c
+++ b/sound/soc/sof/control.c
@@ -141,6 +141,11 @@ int snd_sof_enum_put(struct snd_kcontrol *kcontrol,
struct snd_soc_component *scomp = scontrol->scomp;
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);
+ unsigned int i;
+
+ for (i = 0; i < scontrol->num_channels; i++)
+ if (ucontrol->value.enumerated.item[i] >= se->items)
+ return -EINVAL;
if (tplg_ops && tplg_ops->control && tplg_ops->control->enum_put)
return tplg_ops->control->enum_put(scontrol, ucontrol);
--
2.53.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/4] ASoC: SOF: control: fix volume, switch and enum value handling
2026-11-17 10:59 [PATCH 0/4] ASoC: SOF: control: fix volume, switch and enum value handling Arnav Kapoor
` (3 preceding siblings ...)
2026-11-17 10:59 ` [PATCH 4/4] ASoC: SOF: control: reject out-of-range enum values Arnav Kapoor
@ 2026-11-17 12:24 ` HyeongJun An
4 siblings, 0 replies; 6+ messages in thread
From: HyeongJun An @ 2026-11-17 12:24 UTC (permalink / raw)
To: Arnav Kapoor
Cc: HyeongJun An, Mark Brown, Liam Girdwood, Peter Ujfalusi,
Bard Liao, Daniel Baluta, Ranjani Sridharan, Kai Vehmanen,
Pierre-Louis Bossart, Jaroslav Kysela, Takashi Iwai,
sound-open-firmware, linux-sound, linux-kernel
Hello Arnav,
Patches 1 and 2 overlap with a patch I sent on 2026-11-14:
https://lore.kernel.org/all/20261114021730.2349347-1-sammiee5311@gmail.com/
Mark, I am fine with whichever version you prefer for those two.
Patches 3 and 4 are not covered by mine. I have a Tiger Lake laptop
with SOF and will test the series.
Best regards,
HyeongJun An
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-17 12:25 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 10:59 [PATCH 0/4] ASoC: SOF: control: fix volume, switch and enum value handling Arnav Kapoor
2026-11-17 10:59 ` [PATCH 1/4] ASoC: SOF: control: reject out-of-range volume values Arnav Kapoor
2026-11-17 10:59 ` [PATCH 2/4] ASoC: SOF: control: reject invalid switch values Arnav Kapoor
2026-11-17 10:59 ` [PATCH 3/4] ASoC: SOF: report volume changes in mixer steps Arnav Kapoor
2026-11-17 10:59 ` [PATCH 4/4] ASoC: SOF: control: reject out-of-range enum values Arnav Kapoor
2026-11-17 12:24 ` [PATCH 0/4] ASoC: SOF: control: fix volume, switch and enum value handling HyeongJun An
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®