From: Takashi Iwai <tiwai@suse.de>
To: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
Cc: tiwai@suse.de, linux-kernel@vger.kernel.org,
linux-sound@vger.kernel.org, perex@perex.cz, tiwai@suse.com
Subject: Re: [PATCH v3] ALSA: control: Fix parsing of numeric fields
Date: Mon, 09 Nov 2026 15:33:28 +0100 [thread overview]
Message-ID: <87qzguulaf.wl-tiwai@suse.de> (raw)
In-Reply-To: <20261108124832.3058-1-sreekuttan2156239@gmail.com>
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
prev parent reply other threads:[~2026-11-09 14:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 15:45 [PATCH] " 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
2026-11-09 14:33 ` Takashi Iwai [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87qzguulaf.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=sreekuttan2156239@gmail.com \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®