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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 6bdfd9f1
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include <sys/types.h> #include <sys/types.h>
#include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -30,7 +31,7 @@ get_cpuid(char *buffer, size_t sz) ...@@ -30,7 +31,7 @@ get_cpuid(char *buffer, size_t sz)
buffer[nb-1] = '\0'; buffer[nb-1] = '\0';
return 0; return 0;
} }
return -1; return ENOBUFS;
} }
char * char *
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
*/ */
#include <sys/types.h> #include <sys/types.h>
#include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
...@@ -54,7 +55,7 @@ int get_cpuid(char *buffer, size_t sz) ...@@ -54,7 +55,7 @@ int get_cpuid(char *buffer, size_t sz)
sysinfo = fopen(SYSINFO, "r"); sysinfo = fopen(SYSINFO, "r");
if (sysinfo == NULL) if (sysinfo == NULL)
return -1; return errno;
while ((read = getline(&line, &line_sz, sysinfo)) != -1) { while ((read = getline(&line, &line_sz, sysinfo)) != -1) {
if (!strncmp(line, SYSINFO_MANU, strlen(SYSINFO_MANU))) { if (!strncmp(line, SYSINFO_MANU, strlen(SYSINFO_MANU))) {
...@@ -89,7 +90,7 @@ int get_cpuid(char *buffer, size_t sz) ...@@ -89,7 +90,7 @@ int get_cpuid(char *buffer, size_t sz)
/* Missing manufacturer, type or model information should not happen */ /* Missing manufacturer, type or model information should not happen */
if (!manufacturer[0] || !type[0] || !model[0]) if (!manufacturer[0] || !type[0] || !model[0])
return -1; return EINVAL;
/* /*
* Scan /proc/service_levels and return the CPU-MF counter facility * Scan /proc/service_levels and return the CPU-MF counter facility
...@@ -133,14 +134,14 @@ int get_cpuid(char *buffer, size_t sz) ...@@ -133,14 +134,14 @@ int get_cpuid(char *buffer, size_t sz)
else else
nbytes = snprintf(buffer, sz, "%s,%s,%s", manufacturer, type, nbytes = snprintf(buffer, sz, "%s,%s,%s", manufacturer, type,
model); model);
return (nbytes >= sz) ? -1 : 0; return (nbytes >= sz) ? ENOBUFS : 0;
} }
char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused) char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
{ {
char *buf = malloc(128); char *buf = malloc(128);
if (buf && get_cpuid(buf, 128) < 0) if (buf && get_cpuid(buf, 128))
zfree(&buf); zfree(&buf);
return buf; return buf;
} }
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include <sys/types.h> #include <sys/types.h>
#include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -58,7 +59,7 @@ __get_cpuid(char *buffer, size_t sz, const char *fmt) ...@@ -58,7 +59,7 @@ __get_cpuid(char *buffer, size_t sz, const char *fmt)
buffer[nb-1] = '\0'; buffer[nb-1] = '\0';
return 0; return 0;
} }
return -1; return ENOBUFS;
} }
int int
......
...@@ -705,14 +705,15 @@ static int process_sample_event(struct perf_tool *tool, ...@@ -705,14 +705,15 @@ static int process_sample_event(struct perf_tool *tool,
static int cpu_isa_config(struct perf_kvm_stat *kvm) static int cpu_isa_config(struct perf_kvm_stat *kvm)
{ {
char buf[64], *cpuid; char buf[128], *cpuid;
int err; int err;
if (kvm->live) { if (kvm->live) {
err = get_cpuid(buf, sizeof(buf)); err = get_cpuid(buf, sizeof(buf));
if (err != 0) { if (err != 0) {
pr_err("Failed to look up CPU type\n"); pr_err("Failed to look up CPU type: %s\n",
return err; str_error_r(err, buf, sizeof(buf)));
return -err;
} }
cpuid = buf; cpuid = buf;
} else } else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment