From: Ian Rogers Date: Fri, 6 Dec 2024 04:40:31 +0000 (-0800) Subject: libperf cpumap: Be tolerant of newline at the end of a cpumask X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=5d2fd516bb53e31a2f2e2750490a3f1a7e7edde4;p=users%2Fdwmw2%2Flinux.git libperf cpumap: Be tolerant of newline at the end of a cpumask File cpumasks often have a newline that shouldn't trigger the invalid parsing case in perf_cpu_map__new(). Reviewed-by: Leo Yan Signed-off-by: Ian Rogers Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Ben Gainey Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Kyle Meyer Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20241206044035.1062032-5-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo --- diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index eb02acd962259..f7bde19558e2b 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -241,7 +241,7 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list) p = NULL; start_cpu = strtoul(cpu_list, &p, 0); if (start_cpu >= INT_MAX - || (*p != '\0' && *p != ',' && *p != '-')) + || (*p != '\0' && *p != ',' && *p != '-' && *p != '\n')) goto invalid; if (*p == '-') { @@ -249,7 +249,7 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list) p = NULL; end_cpu = strtoul(cpu_list, &p, 0); - if (end_cpu >= INT_MAX || (*p != '\0' && *p != ',')) + if (end_cpu >= INT_MAX || (*p != '\0' && *p != ',' && *p != '\n')) goto invalid; if (end_cpu < start_cpu)