* Re: [PATCH v3] ALSA: control: Fix parsing of numeric fields
2026-11-08 12:48 ` [PATCH v3] " Sreeraj S Kurup
@ 2026-11-08 16:48 ` Manuel Ebner
2026-11-09 14:33 ` Takashi Iwai
` (2 subsequent siblings)
3 siblings, 0 replies; 13+ messages in thread
From: Manuel Ebner @ 2026-11-08 16:48 UTC (permalink / raw)
To: Sreeraj S Kurup, tiwai; +Cc: linux-kernel, linux-sound, perex, tiwai
On Sun, 2026-11-08 at 12:48 +0000, Sreeraj S Kurup wrote:
> parse_uint() passes the remaining input string to kstrtoull().
>
> When the input contains comma-separated fields, the string
> contains both the numeric value and the following fields.
>
> For example, with:
>
> device=1,subdevice=0,name=Master
>
> kstrtoull() receives "1,subdevice=0,name=Master" and fails
> to parse the numeric value.
>
> Stop parsing at the next comma and pass only the numeric
> field to kstrtouint().
>
> This allows numeric fields to be parsed correctly in
> comma-separated input.
>
> Fixes: a135dfb5de15 ("ALSA: led control - add sysfs kcontrol LED marking layer")
> Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
Reviewed-by: Manuel Ebner
> ---
> v3:
> - No code changes. Retain the v2 implementation after
> comparing the alternative approaches.
> v2:
> - Add the Fixes trailer.
>
> sound/core/control_led.c | 18 +++++++++++++-----
> 1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/sound/core/control_led.c b/sound/core/control_led.c
> index 501387287ae6..3f54af2cb505 100644
> --- a/sound/core/control_led.c
> +++ b/sound/core/control_led.c
> @@ -458,11 +458,19 @@ static char *find_eos(char *s)
>
> static char *parse_uint(char *s, unsigned int *val)
> {
> - unsigned long long res;
> - if (kstrtoull(s, 10, &res))
> - res = 0;
> - *val = res;
> - return find_eos(s);
> + char *end = s;
> + char delimiter;
> +
> + while (*end && *end != ',')
> + end++;
> +
> + delimiter = *end;
> + *end = '\0';
> + if (kstrtouint(s, 10, val))
> + *val = 0;
> + *end = delimiter;
> +
> + return delimiter ? end + 1 : end;
> }
>
> static char *parse_string(char *s, char *val, size_t val_size)
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v3] ALSA: control: Fix parsing of numeric fields
2026-11-08 12:48 ` [PATCH v3] " Sreeraj S Kurup
2026-11-08 16:48 ` Manuel Ebner
@ 2026-11-09 14:33 ` Takashi Iwai
2026-11-09 15:58 ` Sreeraj S Kurup
2026-11-09 15:59 ` [PATCH v4] " Sreeraj S Kurup
2026-11-09 16:35 ` [PATCH v5] " Sreeraj S Kurup
3 siblings, 1 reply; 13+ messages in thread
From: Takashi Iwai @ 2026-11-09 14:33 UTC (permalink / raw)
To: Sreeraj S Kurup; +Cc: tiwai, linux-kernel, linux-sound, perex, tiwai
On Sun, 08 Nov 2026 13:48:32 +0100,
Sreeraj S Kurup wrote:
>
> parse_uint() passes the remaining input string to kstrtoull().
>
> When the input contains comma-separated fields, the string
> contains both the numeric value and the following fields.
>
> For example, with:
>
> device=1,subdevice=0,name=Master
>
> kstrtoull() receives "1,subdevice=0,name=Master" and fails
> to parse the numeric value.
>
> Stop parsing at the next comma and pass only the numeric
> field to kstrtouint().
>
> This allows numeric fields to be parsed correctly in
> comma-separated input.
>
> Fixes: a135dfb5de15 ("ALSA: led control - add sysfs kcontrol LED marking layer")
> Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
> ---
> v3:
> - No code changes. Retain the v2 implementation after
> comparing the alternative approaches.
> v2:
> - Add the Fixes trailer.
I think a bit more easier to understand the code flow would to make
each parse_*() function returning the substring end position, instead
of the next substring. (BTW, this fits more with the function name
find_eos(). too).
The main loop in set_led_id() already treats it,
while (*s) {
os = s;
....
if (*s == ',')
s++;
if (s == os)
break;
}
Both parse_uint() and parse_iface() return find_eos() value as is.
parse_string() has an extra increment for the next substring, so we
just need to drop it.
That is, what we need to change is something like:
--- a/sound/core/control_led.c
+++ b/sound/core/control_led.c
@@ -451,22 +451,24 @@ static const struct attribute_group *snd_ctl_led_dev_attr_groups[] = {
NULL,
};
+/* return the end of substring pointing to either comma or NUL */
static char *find_eos(char *s)
{
while (*s && *s != ',')
s++;
- if (*s)
- s++;
return s;
}
static char *parse_uint(char *s, unsigned int *val)
{
- unsigned long long res;
- if (kstrtoull(s, 10, &res))
- res = 0;
- *val = res;
- return find_eos(s);
+ char *end = find_eos(s);
+ char delimiter = *end;
+
+ *end = '\0';
+ if (kstrtouint(s, 10, val))
+ *val = 0;
+ *end = delimiter;
+ return end;
}
static char *parse_string(char *s, char *val, size_t val_size)
@@ -491,8 +493,6 @@ static char *parse_string(char *s, char *val, size_t val_size)
}
}
*val = '\0';
- if (*s)
- s++;
return s;
}
thanks,
Takashi
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v3] ALSA: control: Fix parsing of numeric fields
2026-11-09 14:33 ` Takashi Iwai
@ 2026-11-09 15:58 ` Sreeraj S Kurup
0 siblings, 0 replies; 13+ messages in thread
From: Sreeraj S Kurup @ 2026-11-09 15:58 UTC (permalink / raw)
To: tiwai; +Cc: linux-kernel, linux-sound, perex, sreekuttan2156239, tiwai
Hi Takashi,
Thanks for the suggestion.
I've updated the patch accordingly. All parse_*() functions
now return the end of the current substring, leaving comma
handling to set_led_id().
I've also updated parse_uint() to temporarily terminate the
numeric substring before calling kstrtouint().
Please find the updated v4 patch.
Thanks,
Sreeraj
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v4] ALSA: control: Fix parsing of numeric fields
2026-11-08 12:48 ` [PATCH v3] " Sreeraj S Kurup
2026-11-08 16:48 ` Manuel Ebner
2026-11-09 14:33 ` Takashi Iwai
@ 2026-11-09 15:59 ` Sreeraj S Kurup
2026-11-09 16:35 ` [PATCH v5] " Sreeraj S Kurup
3 siblings, 0 replies; 13+ messages in thread
From: Sreeraj S Kurup @ 2026-11-09 15:59 UTC (permalink / raw)
To: sreekuttan2156239; +Cc: linux-kernel, linux-sound, perex, tiwai, tiwai
parse_uint() passes the remaining input string to kstrtoull().
When the input contains comma-separated fields, the string
contains both the numeric value and the following fields.
For example, with:
device=1,subdevice=0,name=Master
kstrtoull() receives "1,subdevice=0,name=Master" and fails
to parse the numeric value.
Stop parsing at the next comma and pass only the numeric
field to kstrtouint().
Make all parse_*() functions return the end of the current
substring, leaving delimiter handling to set_led_id().
Temporarily terminate the numeric substring in parse_uint()
before calling kstrtouint().
This allows numeric fields to be parsed correctly in
comma-separated input.
Fixes: a135dfb5de15 ("ALSA: led control - add sysfs kcontrol LED marking layer")
Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
v4:
- Make parse_*() functions consistently return the end of
the current substring.
- Let set_led_id() handle comma advancement.
- Use kstrtouint() after temporarily terminating the
numeric substring.
v3:
- No code changes. Retain the v2 implementation after
comparing the alternative approaches.
v2:
- Add the Fixes trailer.
sound/core/control_led.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/sound/core/control_led.c b/sound/core/control_led.c
index 501387287ae6..1b0473b71c3c 100644
--- a/sound/core/control_led.c
+++ b/sound/core/control_led.c
@@ -447,22 +447,23 @@ static const struct attribute_group *snd_ctl_led_dev_attr_groups[] = {
NULL,
};
+/* return the end of substring pointing to either comma or NUL */
static char *find_eos(char *s)
{
while (*s && *s != ',')
s++;
- if (*s)
- s++;
return s;
}
static char *parse_uint(char *s, unsigned int *val)
{
- unsigned long long res;
- if (kstrtoull(s, 10, &res))
- res = 0;
- *val = res;
- return find_eos(s);
+ char *end = find_eos(s);
+ char delimiter = *end;
+ *end = '\0';
+ if (kstrtouint(s, 10, val))
+ *val = 0;
+ *end = delimiter;
+ return end;
}
static char *parse_string(char *s, char *val, size_t val_size)
@@ -487,8 +488,6 @@ static char *parse_string(char *s, char *val, size_t val_size)
}
}
*val = '\0';
- if (*s)
- s++;
return s;
}
--
2.55.0
^ permalink raw reply [flat|nested] 13+ messages in thread* [PATCH v5] ALSA: control: Fix parsing of numeric fields
2026-11-08 12:48 ` [PATCH v3] " Sreeraj S Kurup
` (2 preceding siblings ...)
2026-11-09 15:59 ` [PATCH v4] " Sreeraj S Kurup
@ 2026-11-09 16:35 ` Sreeraj S Kurup
3 siblings, 0 replies; 13+ messages in thread
From: Sreeraj S Kurup @ 2026-11-09 16:35 UTC (permalink / raw)
To: sreekuttan2156239; +Cc: linux-kernel, linux-sound, perex, tiwai, tiwai
parse_uint() passes the remaining input string to kstrtoull().
When the input contains comma-separated fields, the string
contains both the numeric value and the following fields.
For example, with:
device=1,subdevice=0,name=Master
kstrtoull() receives "1,subdevice=0,name=Master" and fails
to parse the numeric value.
Stop parsing at the next comma and pass only the numeric
field to kstrtouint().
Make all parse_*() functions return the end of the current
substring, leaving delimiter handling to set_led_id().
Temporarily terminate the numeric substring in parse_uint()
before calling kstrtouint().
This allows numeric fields to be parsed correctly in
comma-separated input.
Fixes: a135dfb5de15 ("ALSA: led control - add sysfs kcontrol LED marking layer")
Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
v5:
- Advance past the closing quote in the quoted-string
branch of parse_string().
- Ensure parse_string() returns the end of the current
substring for both quoted and unquoted strings.
v4:
- Make parse_*() functions consistently return the end of
the current substring.
- Let set_led_id() handle comma advancement.
- Use kstrtouint() after temporarily terminating the
numeric substring.
v3:
- No code changes. Retain the v2 implementation after
comparing the alternative approaches.
v2:
- Add the Fixes trailer.
sound/core/control_led.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/sound/core/control_led.c b/sound/core/control_led.c
index 501387287ae6..1aadacfbd3c4 100644
--- a/sound/core/control_led.c
+++ b/sound/core/control_led.c
@@ -447,22 +447,23 @@ static const struct attribute_group *snd_ctl_led_dev_attr_groups[] = {
NULL,
};
+/* return the end of substring pointing to either comma or NUL */
static char *find_eos(char *s)
{
while (*s && *s != ',')
s++;
- if (*s)
- s++;
return s;
}
static char *parse_uint(char *s, unsigned int *val)
{
- unsigned long long res;
- if (kstrtoull(s, 10, &res))
- res = 0;
- *val = res;
- return find_eos(s);
+ char *end = find_eos(s);
+ char delimiter = *end;
+ *end = '\0';
+ if (kstrtouint(s, 10, val))
+ *val = 0;
+ *end = delimiter;
+ return end;
}
static char *parse_string(char *s, char *val, size_t val_size)
@@ -477,6 +478,8 @@ static char *parse_string(char *s, char *val, size_t val_size)
}
s++;
}
+ if (*s)
+ s++;
} else {
while (*s && *s != ',') {
if (val_size > 1) {
@@ -487,8 +490,6 @@ static char *parse_string(char *s, char *val, size_t val_size)
}
}
*val = '\0';
- if (*s)
- s++;
return s;
}
--
2.55.0
^ permalink raw reply [flat|nested] 13+ messages in thread