From 5169bd7647e612a0c93c8f52140565a0388856b1 Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Wed, 1 Jul 2026 12:41:51 -0700 Subject: [PATCH] perf kvm: Do not copy filename string As it removed STRDUP_FAIL_EXIT(), it no longer calls free() for elements in the copied argv. Thus, the filename should not be allocated as well. In fact, it's a pointer to string literals and should be fine to pass the pointer. Tested-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/builtin-kvm.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index eaf9297cc34d..20ea59e59a4b 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -607,11 +607,11 @@ static const char *get_filename_for_perf_kvm(void) const char *filename; if (perf_host && !perf_guest) - filename = strdup("perf.data.host"); + filename = "perf.data.host"; else if (!perf_host && perf_guest) - filename = strdup("perf.data.guest"); + filename = "perf.data.guest"; else - filename = strdup("perf.data.kvm"); + filename = "perf.data.kvm"; return filename; } @@ -2148,15 +2148,9 @@ int cmd_kvm(int argc, const char **argv) if (!perf_host) perf_guest = 1; - if (!file_name) { + if (!file_name) file_name = get_filename_for_perf_kvm(); - if (!file_name) { - pr_err("Failed to allocate memory for filename\n"); - return -ENOMEM; - } - } - if (strlen(argv[0]) > 2 && strstarts("record", argv[0])) return __cmd_record(file_name, argc, argv); else if (strlen(argv[0]) > 2 && strstarts("report", argv[0]))