From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>,
Ian Rogers <irogers@google.com>,
James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-perf-users@vger.kernel.org,
Masami Hiramatsu <mhiramat@kernel.org>
Subject: [PATCH v1 5/8] perf tools: Add dso__put_filename()
Date: Sun, 27 Sep 2026 22:50:52 -0700 [thread overview]
Message-ID: <20260928055055.95144-6-namhyung@kernel.org> (raw)
In-Reply-To: <20260928055055.95144-1-namhyung@kernel.org>
It's a counterpart of the dso__get_filename() as the returned string
should be free. Optionally it needs to remove a temporary file if it's
decompressed on the fly.
Currently the dso argument is not used, but it's better to pair with the
matching dso.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/debuginfo.c | 5 +----
tools/perf/util/dso.c | 28 +++++++++++++---------------
tools/perf/util/dso.h | 2 ++
3 files changed, 16 insertions(+), 19 deletions(-)
diff --git a/tools/perf/util/debuginfo.c b/tools/perf/util/debuginfo.c
index 38e9299765182bd7..fc2640dcd29d3aaa 100644
--- a/tools/perf/util/debuginfo.c
+++ b/tools/perf/util/debuginfo.c
@@ -118,10 +118,7 @@ struct debuginfo *debuginfo__new(const char *path)
return NULL;
dinfo = __debuginfo__new(filename);
-
- if (decomp)
- unlink(filename);
- free(filename);
+ dso__put_filename(dso, filename, decomp);
dso__put(dso);
return dinfo;
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 52f3e78c37220780..0c76441fba82c413 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -661,6 +661,14 @@ char *dso__get_filename(struct dso *dso, const char *root_dir, bool *decomp,
return NULL;
}
+void dso__put_filename(struct dso *dso __maybe_unused, char *filename, bool decomp)
+{
+ if (decomp)
+ unlink(filename);
+
+ free(filename);
+}
+
static int __open_dso(struct dso *dso, struct machine *machine)
EXCLUSIVE_LOCKS_REQUIRED(_dso__data_open_lock)
{
@@ -680,11 +688,8 @@ static int __open_dso(struct dso *dso, struct machine *machine)
fd = -errno;
}
- if (decomp)
- unlink(name);
-
+ dso__put_filename(dso, name, decomp);
mutex_unlock(dso__lock(dso));
- free(name);
return fd;
}
@@ -2088,14 +2093,11 @@ struct debuginfo *dso__debuginfo(struct dso *dso)
mutex_lock(dso__lock(dso));
name = dso__get_filename(dso, "", &decomp, dso__dbginfo_type(dso));
- if (name)
+ if (name) {
dinfo = debuginfo__new(name);
-
- if (decomp)
- unlink(name);
-
+ dso__put_filename(dso, name, decomp);
+ }
mutex_unlock(dso__lock(dso));
- free(name);
return dinfo;
}
@@ -2133,11 +2135,7 @@ void dso__find_dbginfo_type(struct dso *dso)
continue;
found = filename__has_section(path, ".debug_info");
-
- if (decomp)
- unlink(path);
- free(path);
-
+ dso__put_filename(dso, path, decomp);
if (found)
break;
}
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index 94cc7ea89ceb5bd9..45c4954d5eaf9ffa 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -841,8 +841,10 @@ int dso__kernel_module_get_build_id(struct dso *dso, const char *root_dir);
char dso__symtab_origin(const struct dso *dso);
int dso__read_binary_type_filename(const struct dso *dso, enum dso_binary_type type,
const char *root_dir, char *filename, size_t size);
+/* returned filename should be freed by dso__put_filename() */
char *dso__get_filename(struct dso *dso, const char *root_dir, bool *decomp,
enum dso_binary_type type);
+void dso__put_filename(struct dso *dso, char *filename, bool decomp);
bool is_kernel_module(const char *pathname, int cpumode);
bool dso__needs_decompress(struct dso *dso);
int dso__decompress_kmodule_fd(struct dso *dso, const char *name);
--
2.55.0
next prev parent reply other threads:[~2026-09-28 5:51 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 5:50 [PATCH v1 0/8] perf tools: Cleanup dso debug info access Namhyung Kim
2026-09-28 5:50 ` [PATCH v1 1/8] perf tools: Add dso->dbginfo_type field Namhyung Kim
2026-09-28 5:57 ` sashiko-bot
2026-09-28 5:50 ` [PATCH v1 2/8] perf tools: Factor out dso__find_dbginfo_type() Namhyung Kim
2026-09-28 5:58 ` sashiko-bot
2026-09-28 5:50 ` [PATCH v1 3/8] perf tools: Check system path when check debuginfo Namhyung Kim
2026-09-28 5:59 ` sashiko-bot
2026-09-29 0:37 ` Namhyung Kim
2026-09-28 5:50 ` [PATCH v1 4/8] perf tools: Export dso__get_filename() with type argument Namhyung Kim
2026-09-28 6:13 ` sashiko-bot
2026-09-28 5:50 ` Namhyung Kim [this message]
2026-09-28 5:56 ` [PATCH v1 5/8] perf tools: Add dso__put_filename() sashiko-bot
2026-09-28 5:50 ` [PATCH v1 6/8] perf tools: Avoid repeated failing search for debuginfo Namhyung Kim
2026-09-28 6:08 ` sashiko-bot
2026-09-28 5:50 ` [PATCH v1 7/8] perf tools: Looks symbol file first when check debuginfo Namhyung Kim
2026-09-28 6:10 ` sashiko-bot
2026-09-28 5:50 ` [PATCH v1 8/8] perf tools: Update debuginfo__new() to take DSO Namhyung Kim
2026-09-28 6:02 ` sashiko-bot
2026-09-28 16:45 ` [PATCH v1 0/8] perf tools: Cleanup dso debug info access Arnaldo Carvalho de Melo
2026-09-29 0:38 ` Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260928055055.95144-6-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.