rtla: Fix parse_cpu_set() bug introduced by strtoi()

The patch 'Replace atoi() with a robust strtoi()' introduced a bug
in parse_cpu_set(), which relies on partial parsing of the input string.

The function parses CPU specifications like '0-3,5' by incrementing
a pointer through the string. strtoi() rejects strings with trailing
characters, causing parse_cpu_set() to fail on any CPU list with
multiple entries.

Restore the original use of atoi() in parse_cpu_set().

Fixes: 7e9dfccf8f ("rtla: Replace atoi() with a robust strtoi()")
Signed-off-by: Costa Shulyupin <costa.shul@redhat.com>
Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Link: https://lore.kernel.org/r/20260112192642.212848-2-costa.shul@redhat.com
Signed-off-by: Tomas Glozar <tglozar@redhat.com>
This commit is contained in:
Costa Shulyupin 2026-01-12 21:26:41 +02:00 committed by Tomas Glozar
parent fb8b818320
commit 6ea8a20610

View file

@ -128,18 +128,16 @@ int parse_cpu_set(char *cpu_list, cpu_set_t *set)
nr_cpus = sysconf(_SC_NPROCESSORS_CONF); nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
for (p = cpu_list; *p; ) { for (p = cpu_list; *p; ) {
if (strtoi(p, &cpu)) cpu = atoi(p);
goto err; if (cpu < 0 || (!cpu && *p != '0') || cpu >= nr_cpus)
if (cpu < 0 || cpu >= nr_cpus)
goto err; goto err;
while (isdigit(*p)) while (isdigit(*p))
p++; p++;
if (*p == '-') { if (*p == '-') {
p++; p++;
if (strtoi(p, &end_cpu)) end_cpu = atoi(p);
goto err; if (end_cpu < cpu || (!end_cpu && *p != '0') || end_cpu >= nr_cpus)
if (end_cpu < cpu || end_cpu >= nr_cpus)
goto err; goto err;
while (isdigit(*p)) while (isdigit(*p))
p++; p++;