From: Dapeng Mi Date: Tue, 3 Feb 2026 02:43:53 +0000 (+0800) Subject: perf regs: Fix abort for "-I" or "--user-regs" options X-Git-Tag: v7.0-rc1~16^2~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c2e28ae2946f473d6c340ebbeac0cf87be46d582;p=thirdparty%2Fkernel%2Fstable.git perf regs: Fix abort for "-I" or "--user-regs" options Fix an issue where the `perf` tool aborts unexpectedly when running the following command: ``` perf record -e cycles -I -- true Usage: perf record [] [] or: perf record [] -- [] -I, --intr-regs[=] sample selected machine registers on interrupt, use '-I?' to list register names ``` The usage of the `-I` or `--user-regs` options without specifying any registers should default to sampling all general-purpose registers. However, this currently causes an abnormal termination. The issue was introduced by commit 3d06db9bad1a ("perf regs: Refactor use of arch__sample_reg_masks() to perf_reg_name()"). This patch resolves the problem, ensuring that the `-I` or `--user-regs` options work as intended without causing an abort. Fixes: 3d06db9bad1ad8e6 ("perf regs: Refactor use of arch__sample_reg_masks() to perf_reg_name()") Reviewed-by: Ian Rogers Signed-off-by: Dapeng Mi Cc: Adrian Hunter Cc: Albert Ou Cc: Alexander Shishkin Cc: Alexandre Ghiti Cc: Guo Ren Cc: Ian Rogers Cc: Ingo Molnar Cc: James Clark Cc: John Garry Cc: linux-arm-kernel@lists.infradead.org Cc: linux-csky@vger.kernel.org Cc: linux-riscv@lists.infradead.org Cc: Mike Leach Cc: Namhyung Kim Cc: Palmer Dabbelt Cc: Paul Walmsley Cc: Peter Zijlstra Cc: Thomas Falcon Cc: Will Deacon Cc: Xudong Hao Cc: Zide Chen Signed-off-by: Arnaldo Carvalho de Melo --- diff --git a/tools/perf/util/parse-regs-options.c b/tools/perf/util/parse-regs-options.c index 8dd35f50f6446..b44b47d9059fd 100644 --- a/tools/perf/util/parse-regs-options.c +++ b/tools/perf/util/parse-regs-options.c @@ -66,12 +66,14 @@ __parse_regs(const struct option *opt, const char *str, int unset, bool intr) if (*mode) return -1; - /* str may be NULL in case no arg is passed to -I */ - if (!str) - return -1; - mask = intr ? arch__intr_reg_mask() : arch__user_reg_mask(); + /* str may be NULL in case no arg is passed to -I */ + if (!str) { + *mode = mask; + return 0; + } + /* because str is read-only */ s = os = strdup(str); if (!s) @@ -104,9 +106,6 @@ __parse_regs(const struct option *opt, const char *str, int unset, bool intr) } ret = 0; - /* default to all possible regs */ - if (*mode == 0) - *mode = mask; error: free(os); return ret;