Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf data convert: Fix segfault when converting to json when cpu_desc isn't set

Arm64 doesn't have Model in /proc/cpuinfo and, thus, cpu_desc doesn't get
assigned.

Running
$ perf data convert --to-json perf.data.json

ends up calling output_json_string() with NULL pointer, which causes a
segmentation fault.

Signed-off-by: Ilkka Koskinen <ilkka@os.amperecomputing.com>
Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Evgeny Pistun <kotborealis@awooo.ru>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240223220458.15282-1-ilkka@os.amperecomputing.com

authored by

Ilkka Koskinen and committed by
Namhyung Kim
bae4d1f8 529d5818

+3 -1
+3 -1
tools/perf/util/data-convert-json.c
··· 284 284 output_json_key_string(out, true, 2, "os-release", header->env.os_release); 285 285 output_json_key_string(out, true, 2, "arch", header->env.arch); 286 286 287 - output_json_key_string(out, true, 2, "cpu-desc", header->env.cpu_desc); 287 + if (header->env.cpu_desc) 288 + output_json_key_string(out, true, 2, "cpu-desc", header->env.cpu_desc); 289 + 288 290 output_json_key_string(out, true, 2, "cpuid", header->env.cpuid); 289 291 output_json_key_format(out, true, 2, "nrcpus-online", "%u", header->env.nr_cpus_online); 290 292 output_json_key_format(out, true, 2, "nrcpus-avail", "%u", header->env.nr_cpus_avail);