Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Refactor out kernel symbol argument sanity checking

User supplied values for vmlinux and kallsyms are checked before
continuing. Refactor this into a function so that it can be used
elsewhere.

Reviewed-by: Denis Nikitin <denik@chromium.org>
Signed-off-by: James Clark <james.clark@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20211018134844.2627174-2-james.clark@arm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

James Clark and committed by
Arnaldo Carvalho de Melo
a3df50ab 1a86f4ba

+26 -11
+2 -11
tools/perf/builtin-report.c
··· 1378 1378 if (quiet) 1379 1379 perf_quiet_option(); 1380 1380 1381 - if (symbol_conf.vmlinux_name && 1382 - access(symbol_conf.vmlinux_name, R_OK)) { 1383 - pr_err("Invalid file: %s\n", symbol_conf.vmlinux_name); 1384 - ret = -EINVAL; 1381 + ret = symbol__validate_sym_arguments(); 1382 + if (ret) 1385 1383 goto exit; 1386 - } 1387 - if (symbol_conf.kallsyms_name && 1388 - access(symbol_conf.kallsyms_name, R_OK)) { 1389 - pr_err("Invalid file: %s\n", symbol_conf.kallsyms_name); 1390 - ret = -EINVAL; 1391 - goto exit; 1392 - } 1393 1384 1394 1385 if (report.inverted_callchain) 1395 1386 callchain_param.order = ORDER_CALLER;
+22
tools/perf/util/symbol.c
··· 2634 2634 refcount_set(&mi->refcnt, 1); 2635 2635 return mi; 2636 2636 } 2637 + 2638 + /* 2639 + * Checks that user supplied symbol kernel files are accessible because 2640 + * the default mechanism for accessing elf files fails silently. i.e. if 2641 + * debug syms for a build ID aren't found perf carries on normally. When 2642 + * they are user supplied we should assume that the user doesn't want to 2643 + * silently fail. 2644 + */ 2645 + int symbol__validate_sym_arguments(void) 2646 + { 2647 + if (symbol_conf.vmlinux_name && 2648 + access(symbol_conf.vmlinux_name, R_OK)) { 2649 + pr_err("Invalid file: %s\n", symbol_conf.vmlinux_name); 2650 + return -EINVAL; 2651 + } 2652 + if (symbol_conf.kallsyms_name && 2653 + access(symbol_conf.kallsyms_name, R_OK)) { 2654 + pr_err("Invalid file: %s\n", symbol_conf.kallsyms_name); 2655 + return -EINVAL; 2656 + } 2657 + return 0; 2658 + }
+2
tools/perf/util/symbol.h
··· 286 286 287 287 #define mem_info__zput(mi) __mem_info__zput(&mi) 288 288 289 + int symbol__validate_sym_arguments(void); 290 + 289 291 #endif /* __PERF_SYMBOL */