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>
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -54,7 +55,7 @@ int get_cpuid(char *buffer, size_t sz)
|
||||
|
||||
sysinfo = fopen(SYSINFO, "r");
|
||||
if (sysinfo == NULL)
|
||||
return -1;
|
||||
return errno;
|
||||
|
||||
while ((read = getline(&line, &line_sz, sysinfo)) != -1) {
|
||||
if (!strncmp(line, SYSINFO_MANU, strlen(SYSINFO_MANU))) {
|
||||
@@ -89,7 +90,7 @@ int get_cpuid(char *buffer, size_t sz)
|
||||
|
||||
/* Missing manufacturer, type or model information should not happen */
|
||||
if (!manufacturer[0] || !type[0] || !model[0])
|
||||
return -1;
|
||||
return EINVAL;
|
||||
|
||||
/*
|
||||
* Scan /proc/service_levels and return the CPU-MF counter facility
|
||||
@@ -133,14 +134,14 @@ skip_sysinfo:
|
||||
else
|
||||
nbytes = snprintf(buffer, sz, "%s,%s,%s", manufacturer, type,
|
||||
model);
|
||||
return (nbytes >= sz) ? -1 : 0;
|
||||
return (nbytes >= sz) ? ENOBUFS : 0;
|
||||
}
|
||||
|
||||
char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
|
||||
{
|
||||
char *buf = malloc(128);
|
||||
|
||||
if (buf && get_cpuid(buf, 128) < 0)
|
||||
if (buf && get_cpuid(buf, 128))
|
||||
zfree(&buf);
|
||||
return buf;
|
||||
}
|
||||
|
Reference in New Issue
Block a user