Skip to content

Commit 92294b9

Browse files
captain5050acmel
authored andcommitted
perf daemon: Dynamically allocate path to perf
Avoid a PATH_MAX array in __daemon (the .data section) by dynamically allocating the memory. Signed-off-by: Ian Rogers <irogers@google.com> Link: https://lore.kernel.org/r/20230526183401.2326121-9-irogers@google.com Cc: K Prateek Nayak <kprateek.nayak@amd.com> Cc: Ravi Bangoria <ravi.bangoria@amd.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Ross Zwisler <zwisler@chromium.org> Cc: Steven Rostedt (Google) <rostedt@goodmis.org> Cc: Sean Christopherson <seanjc@google.com> Cc: Yang Jihong <yangjihong1@huawei.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Masami Hiramatsu (Google) <mhiramat@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Leo Yan <leo.yan@linaro.org> Cc: Andi Kleen <ak@linux.intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Tiezhu Yang <yangtiezhu@loongson.cn> Cc: Ingo Molnar <mingo@redhat.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: linux-kernel@vger.kernel.org Cc: linux-perf-users@vger.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 20dcad8 commit 92294b9

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

tools/perf/builtin-daemon.c

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ struct daemon {
9090
char *base;
9191
struct list_head sessions;
9292
FILE *out;
93-
char perf[PATH_MAX];
93+
char *perf;
9494
int signal_fd;
9595
time_t start;
9696
};
@@ -1490,6 +1490,14 @@ static int __cmd_ping(struct daemon *daemon, struct option parent_options[],
14901490
return send_cmd(daemon, &cmd);
14911491
}
14921492

1493+
static char *alloc_perf_exe_path(void)
1494+
{
1495+
char path[PATH_MAX];
1496+
1497+
perf_exe(path, sizeof(path));
1498+
return strdup(path);
1499+
}
1500+
14931501
int cmd_daemon(int argc, const char **argv)
14941502
{
14951503
struct option daemon_options[] = {
@@ -1502,31 +1510,35 @@ int cmd_daemon(int argc, const char **argv)
15021510
"field separator", "print counts with custom separator", ","),
15031511
OPT_END()
15041512
};
1513+
int ret = -1;
1514+
1515+
__daemon.perf = alloc_perf_exe_path();
1516+
if (!__daemon.perf)
1517+
return -ENOMEM;
15051518

1506-
perf_exe(__daemon.perf, sizeof(__daemon.perf));
15071519
__daemon.out = stdout;
15081520

15091521
argc = parse_options(argc, argv, daemon_options, daemon_usage,
15101522
PARSE_OPT_STOP_AT_NON_OPTION);
15111523

15121524
if (argc) {
15131525
if (!strcmp(argv[0], "start"))
1514-
return __cmd_start(&__daemon, daemon_options, argc, argv);
1526+
ret = __cmd_start(&__daemon, daemon_options, argc, argv);
15151527
if (!strcmp(argv[0], "signal"))
1516-
return __cmd_signal(&__daemon, daemon_options, argc, argv);
1528+
ret = __cmd_signal(&__daemon, daemon_options, argc, argv);
15171529
else if (!strcmp(argv[0], "stop"))
1518-
return __cmd_stop(&__daemon, daemon_options, argc, argv);
1530+
ret = __cmd_stop(&__daemon, daemon_options, argc, argv);
15191531
else if (!strcmp(argv[0], "ping"))
1520-
return __cmd_ping(&__daemon, daemon_options, argc, argv);
1521-
1522-
pr_err("failed: unknown command '%s'\n", argv[0]);
1523-
return -1;
1524-
}
1525-
1526-
if (setup_config(&__daemon)) {
1527-
pr_err("failed: config not found\n");
1528-
return -1;
1532+
ret = __cmd_ping(&__daemon, daemon_options, argc, argv);
1533+
else
1534+
pr_err("failed: unknown command '%s'\n", argv[0]);
1535+
} else {
1536+
ret = setup_config(&__daemon);
1537+
if (ret)
1538+
pr_err("failed: config not found\n");
1539+
else
1540+
ret = send_cmd_list(&__daemon);
15291541
}
1530-
1531-
return send_cmd_list(&__daemon);
1542+
zfree(&__daemon.perf);
1543+
return ret;
15321544
}

0 commit comments

Comments
 (0)