[PATCH v2 5/6] perf build-id: Simplify build_id_cache__cachedir

Ian Rogers irogers at google.com
Thu Aug 24 19:40:01 PDT 2023


Initialize realname to NULL, rather than name. This avoids a cast and
as realpath is either NULL or an allocated string, free can be called
unconditionally.

Signed-off-by: Ian Rogers <irogers at google.com>
---
 tools/perf/util/build-id.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index 36728222a5b4..03c64b85383b 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -560,7 +560,7 @@ char *build_id_cache__cachedir(const char *sbuild_id, const char *name,
 			       struct nsinfo *nsi, bool is_kallsyms,
 			       bool is_vdso)
 {
-	char *realname = (char *)name, *filename;
+	char *realname = NULL, *filename;
 	bool slash = is_kallsyms || is_vdso;
 
 	if (!slash)
@@ -571,9 +571,7 @@ char *build_id_cache__cachedir(const char *sbuild_id, const char *name,
 		     sbuild_id ? "/" : "", sbuild_id ?: "") < 0)
 		filename = NULL;
 
-	if (!slash)
-		free(realname);
-
+	free(realname);
 	return filename;
 }
 
-- 
2.42.0.rc2.253.gd59a3bf2b4-goog




More information about the linux-arm-kernel mailing list