* [PATCH] ALSA: control: Fix parsing of numeric fields
@ 2026-11-06 15:45 Sreeraj S Kurup
2026-11-06 16:23 ` [PATCH v2] " Sreeraj S Kurup
0 siblings, 1 reply; 9+ messages in thread
From: Sreeraj S Kurup @ 2026-11-06 15:45 UTC (permalink / raw)
To: tiwai, perex, tiwai; +Cc: linux-kernel, linux-sound, Sreeraj S Kurup
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.
Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
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)
--
2.55.0
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH v2] ALSA: control: Fix parsing of numeric fields
2026-11-06 15:45 [PATCH] ALSA: control: Fix parsing of numeric fields Sreeraj S Kurup
@ 2026-11-06 16:23 ` Sreeraj S Kurup
2026-11-08 9:54 ` Sreeraj S Kurup
0 siblings, 1 reply; 9+ messages in thread
From: Sreeraj S Kurup @ 2026-11-06 16:23 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().
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>
---
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)
--
2.55.0
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH v2] ALSA: control: Fix parsing of numeric fields
2026-11-06 16:23 ` [PATCH v2] " Sreeraj S Kurup
@ 2026-11-08 9:54 ` Sreeraj S Kurup
2026-11-08 10:44 ` Takashi Iwai
0 siblings, 1 reply; 9+ messages in thread
From: Sreeraj S Kurup @ 2026-11-08 9:54 UTC (permalink / raw)
To: sreekuttan2156239; +Cc: linux-kernel, linux-sound, perex, tiwai, tiwai
Hi Takashi,
I looked into using simple_strtoul(), but noticed that it is deprecated.
kstrtoul() does not provide an end pointer either.
Would it be reasonable to retain the delimiter-first approach with
kstrtouint(), as in v2?
Thanks,
Sreeraj
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] ALSA: control: Fix parsing of numeric fields
2026-11-08 9:54 ` Sreeraj S Kurup
@ 2026-11-08 10:44 ` Takashi Iwai
2026-11-08 11:18 ` Sreeraj S Kurup
0 siblings, 1 reply; 9+ messages in thread
From: Takashi Iwai @ 2026-11-08 10:44 UTC (permalink / raw)
To: Sreeraj S Kurup; +Cc: linux-kernel, linux-sound, perex, tiwai, tiwai
On Sun, 08 Nov 2026 10:54:30 +0100,
Sreeraj S Kurup wrote:
>
> Hi Takashi,
>
> I looked into using simple_strtoul(), but noticed that it is deprecated.
> kstrtoul() does not provide an end pointer either.
Yes, that's also my concern about that approach.
> Would it be reasonable to retain the delimiter-first approach with
> kstrtouint(), as in v2?
I depends on the result :) We can compare.
thanks,
Takashi
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] ALSA: control: Fix parsing of numeric fields
2026-11-08 10:44 ` Takashi Iwai
@ 2026-11-08 11:18 ` Sreeraj S Kurup
2026-11-08 12:06 ` Takashi Iwai
0 siblings, 1 reply; 9+ messages in thread
From: Sreeraj S Kurup @ 2026-11-08 11:18 UTC (permalink / raw)
To: tiwai; +Cc: linux-kernel, linux-sound, perex, sreekuttan2156239, tiwai
Hi Takashi,
I compared the approaches.
Using simple_strtoul() would provide an end pointer, but it is deprecated.
Another option is to retain kstrtoull() from the original implementation
and apply the delimiter-first approach. This would minimize changes to the
existing conversion logic.
However, since the destination is an unsigned int, kstrtouint() better matches
the destination type and also detects values outside the unsigned int range.
I currently prefer the v2 approach, but wanted to point out this difference in
overflow handling.
Thanks,
Sreeraj
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] ALSA: control: Fix parsing of numeric fields
2026-11-08 11:18 ` Sreeraj S Kurup
@ 2026-11-08 12:06 ` Takashi Iwai
2026-11-08 12:47 ` Sreeraj S Kurup
2026-11-08 12:48 ` [PATCH v3] " Sreeraj S Kurup
0 siblings, 2 replies; 9+ messages in thread
From: Takashi Iwai @ 2026-11-08 12:06 UTC (permalink / raw)
To: Sreeraj S Kurup; +Cc: tiwai, linux-kernel, linux-sound, perex, tiwai
On Sun, 08 Nov 2026 12:18:48 +0100,
Sreeraj S Kurup wrote:
>
> Hi Takashi,
>
> I compared the approaches.
>
> Using simple_strtoul() would provide an end pointer, but it is deprecated.
>
> Another option is to retain kstrtoull() from the original implementation
> and apply the delimiter-first approach. This would minimize changes to the
> existing conversion logic.
>
> However, since the destination is an unsigned int, kstrtouint() better matches
> the destination type and also detects values outside the unsigned int range.
>
> I currently prefer the v2 approach, but wanted to point out this difference in
> overflow handling.
OK, thanks. Feel free to resubmit whatever you find better :)
Takashi
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] ALSA: control: Fix parsing of numeric fields
2026-11-08 12:06 ` Takashi Iwai
@ 2026-11-08 12:47 ` Sreeraj S Kurup
2026-11-08 12:48 ` [PATCH v3] " Sreeraj S Kurup
1 sibling, 0 replies; 9+ messages in thread
From: Sreeraj S Kurup @ 2026-11-08 12:47 UTC (permalink / raw)
To: tiwai; +Cc: linux-kernel, linux-sound, perex, sreekuttan2156239, tiwai
Hi Takashi,
Thanks. I'll resubmit v2.
Thanks, Sreeraj
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v3] ALSA: control: Fix parsing of numeric fields
2026-11-08 12:06 ` Takashi Iwai
2026-11-08 12:47 ` Sreeraj S Kurup
@ 2026-11-08 12:48 ` Sreeraj S Kurup
2026-11-08 16:48 ` Manuel Ebner
1 sibling, 1 reply; 9+ messages in thread
From: Sreeraj S Kurup @ 2026-11-08 12:48 UTC (permalink / raw)
To: tiwai; +Cc: linux-kernel, linux-sound, perex, sreekuttan2156239, 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().
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.
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)
--
2.55.0
^ permalink raw reply [flat|nested] 9+ 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
0 siblings, 0 replies; 9+ 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] 9+ messages in thread
end of thread, other threads:[~2026-11-08 16:48 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-06 15:45 [PATCH] ALSA: control: Fix parsing of numeric fields Sreeraj S Kurup
2026-11-06 16:23 ` [PATCH v2] " Sreeraj S Kurup
2026-11-08 9:54 ` Sreeraj S Kurup
2026-11-08 10:44 ` Takashi Iwai
2026-11-08 11:18 ` Sreeraj S Kurup
2026-11-08 12:06 ` Takashi Iwai
2026-11-08 12:47 ` Sreeraj S Kurup
2026-11-08 12:48 ` [PATCH v3] " Sreeraj S Kurup
2026-11-08 16:48 ` Manuel Ebner
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®