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

perf tools: Propagate get_cpuid() error

For consistency, propagate the exact cause for get_cpuid() to have
failed.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-9ig269f7ktnhh99g4l15vpu2@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+13 -9
+2 -1
tools/perf/arch/powerpc/util/header.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include <sys/types.h> 3 + #include <errno.h> 3 4 #include <unistd.h> 4 5 #include <stdio.h> 5 6 #include <stdlib.h> ··· 31 30 buffer[nb-1] = '\0'; 32 31 return 0; 33 32 } 34 - return -1; 33 + return ENOBUFS; 35 34 } 36 35 37 36 char *
+5 -4
tools/perf/arch/s390/util/header.c
··· 8 8 */ 9 9 10 10 #include <sys/types.h> 11 + #include <errno.h> 11 12 #include <unistd.h> 12 13 #include <stdio.h> 13 14 #include <string.h> ··· 55 54 56 55 sysinfo = fopen(SYSINFO, "r"); 57 56 if (sysinfo == NULL) 58 - return -1; 57 + return errno; 59 58 60 59 while ((read = getline(&line, &line_sz, sysinfo)) != -1) { 61 60 if (!strncmp(line, SYSINFO_MANU, strlen(SYSINFO_MANU))) { ··· 90 89 91 90 /* Missing manufacturer, type or model information should not happen */ 92 91 if (!manufacturer[0] || !type[0] || !model[0]) 93 - return -1; 92 + return EINVAL; 94 93 95 94 /* 96 95 * Scan /proc/service_levels and return the CPU-MF counter facility ··· 134 133 else 135 134 nbytes = snprintf(buffer, sz, "%s,%s,%s", manufacturer, type, 136 135 model); 137 - return (nbytes >= sz) ? -1 : 0; 136 + return (nbytes >= sz) ? ENOBUFS : 0; 138 137 } 139 138 140 139 char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused) 141 140 { 142 141 char *buf = malloc(128); 143 142 144 - if (buf && get_cpuid(buf, 128) < 0) 143 + if (buf && get_cpuid(buf, 128)) 145 144 zfree(&buf); 146 145 return buf; 147 146 }
+2 -1
tools/perf/arch/x86/util/header.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include <sys/types.h> 3 + #include <errno.h> 3 4 #include <unistd.h> 4 5 #include <stdio.h> 5 6 #include <stdlib.h> ··· 59 58 buffer[nb-1] = '\0'; 60 59 return 0; 61 60 } 62 - return -1; 61 + return ENOBUFS; 63 62 } 64 63 65 64 int
+4 -3
tools/perf/builtin-kvm.c
··· 705 705 706 706 static int cpu_isa_config(struct perf_kvm_stat *kvm) 707 707 { 708 - char buf[64], *cpuid; 708 + char buf[128], *cpuid; 709 709 int err; 710 710 711 711 if (kvm->live) { 712 712 err = get_cpuid(buf, sizeof(buf)); 713 713 if (err != 0) { 714 - pr_err("Failed to look up CPU type\n"); 715 - return err; 714 + pr_err("Failed to look up CPU type: %s\n", 715 + str_error_r(err, buf, sizeof(buf))); 716 + return -err; 716 717 } 717 718 cpuid = buf; 718 719 } else