[PATCH v2] ALSA: control: Trim whitespace from sysfs input

From: Sreeraj S Kurup

Date: Fri Nov 06 2026 - 12:27:20 EST


The attach and detach sysfs interfaces receive input from
userspace.

When userspace writes a value using echo, the input normally
ends with a newline character.

The parser does not remove this newline in all input formats.
For example, a bare numeric ID can be treated as a control name,
and an unquoted name= field can include the newline.

Trim leading and trailing whitespace before parsing the input.

This keeps spaces inside mixer control names unchanged.

Fixes: a135dfb5de15 ("ALSA: led control - add sysfs kcontrol LED marking layer")
Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@xxxxxxxxx>
---
v2:
- Add the Fixes trailer.

sound/core/control_led.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/sound/core/control_led.c b/sound/core/control_led.c
index 501387287ae6..a640e7835ce2 100644
--- a/sound/core/control_led.c
+++ b/sound/core/control_led.c
@@ -518,6 +518,11 @@ static ssize_t set_led_id(struct snd_ctl_led_card *led_card, const char *buf, si

if (strscpy(buf2, buf, sizeof(buf2)) < 0)
return -E2BIG;
+
+ s = strim(buf2);
+ if (s != buf2)
+ memmove(buf2, s, strlen(s) + 1);
+
memset(&id, 0, sizeof(id));
id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
s = buf2;
--
2.55.0