[PATCH v7 2/9] perf config: Make perf_etc_perfconfig() never return NULL
From: Arnaldo Carvalho de Melo
Date: Thu Oct 01 2026 - 14:54:33 EST
From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
perf_etc_perfconfig() returns what system_path() gives, and that
allocates, so on failure every caller dereferenced NULL, the
pre-existing ones in perf_config_set__init() and in the daemon
included. For the usual absolute ETC_PERFCONFIG system_path() just
returns a strdup of it, so use ETC_PERFCONFIG itself when that fails.
Assisted-by: LLM
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/util/config.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index 85e50d0a25580da0..6e0ff8a9140ccf96 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -571,8 +571,14 @@ static int perf_config_from_file(config_fn_t fn, const char *filename, void *dat
const char *perf_etc_perfconfig(void)
{
static const char *system_wide;
+
if (!system_wide)
- system_wide = system_path(ETC_PERFCONFIG);
+ /*
+ * ETC_PERFCONFIG is absolute, so its unresolved path is
+ * the same string, better than the callers crashing.
+ */
+ system_wide = system_path(ETC_PERFCONFIG) ?: ETC_PERFCONFIG;
+
return system_wide;
}
--
2.55.0