[PATCH v7 04/23] perf kwork: Duplicate IRQ name in irq_work_init

Ian Rogers
2026-04-08T07:26:16Z

The IRQ name was set to a pointer within an event, making the lifetime
memory management most likely a bug. In other instances the name for
kwork_work is allocated, such as in evsel__softirq_name. Match that
pattern by strdup-ing the name from the sample.

Make the return type of perf_sample__strval a "const char *" rather
than a "char *" as mutating the contents of an event through the
sample isn't expected.

Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/builtin-kwork.c | 2 +-
tools/perf/util/evsel.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c
index f600037ee460..dceb9b79aa6a 100644
--- a/tools/perf/builtin-kwork.c
+++ b/tools/perf/builtin-kwork.c
@@ -1018,7 +1018,7 @@ static void irq_work_init(struct perf_kwork *kwork,
work->name = NULL;
} else {
work->id = perf_sample__intval(sample, "irq");
- work->name = perf_sample__strval(sample, "name");
+ work->name = strdup(perf_sample__strval(sample, "name") ?: "<unknown>");
}
}

diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 927e5b4756cc..cf495829dbb0 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -376,7 +376,7 @@ u64 perf_sample__intval(struct perf_sample *sample, const char *name);
u64 perf_sample__intval_common(struct perf_sample *sample, const char *name);
char perf_sample__taskstate(struct perf_sample *sample, const char *name);

-static inline char *perf_sample__strval(struct perf_sample *sample, const char *name)
+static inline const char *perf_sample__strval(struct perf_sample *sample, const char *name)
{
return perf_sample__rawptr(sample, name);
}
--
2.53.0.1213.gd9a14994de-goog