mirror of
https://github.com/torvalds/linux.git
synced 2024-12-11 05:33:09 +00:00
perf pmu: Add proper error handling to print_pmu_events()
It was silently returning or printing "(null)" when no memory was available at various points. Fix it by checking and warning the user when that happens. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Borislav Petkov <bp@suse.de> Cc: David Ahern <dsahern@gmail.com> Cc: Don Zickus <dzickus@redhat.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jean Pihet <jean.pihet@linaro.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-835udmf66x9nza504cu6irz9@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
46b1fa85ff
commit
7e4772dc99
@ -753,9 +753,9 @@ void print_pmu_events(const char *event_glob, bool name_only)
|
|||||||
if (pmu->selectable)
|
if (pmu->selectable)
|
||||||
len++;
|
len++;
|
||||||
}
|
}
|
||||||
aliases = malloc(sizeof(char *) * len);
|
aliases = zalloc(sizeof(char *) * len);
|
||||||
if (!aliases)
|
if (!aliases)
|
||||||
return;
|
goto out_enomem;
|
||||||
pmu = NULL;
|
pmu = NULL;
|
||||||
j = 0;
|
j = 0;
|
||||||
while ((pmu = perf_pmu__scan(pmu)) != NULL) {
|
while ((pmu = perf_pmu__scan(pmu)) != NULL) {
|
||||||
@ -768,16 +768,20 @@ void print_pmu_events(const char *event_glob, bool name_only)
|
|||||||
(!is_cpu && strglobmatch(alias->name,
|
(!is_cpu && strglobmatch(alias->name,
|
||||||
event_glob))))
|
event_glob))))
|
||||||
continue;
|
continue;
|
||||||
aliases[j] = name;
|
|
||||||
if (is_cpu && !name_only)
|
if (is_cpu && !name_only)
|
||||||
aliases[j] = format_alias_or(buf, sizeof(buf),
|
name = format_alias_or(buf, sizeof(buf), pmu, alias);
|
||||||
pmu, alias);
|
|
||||||
aliases[j] = strdup(aliases[j]);
|
aliases[j] = strdup(name);
|
||||||
|
if (aliases[j] == NULL)
|
||||||
|
goto out_enomem;
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
if (pmu->selectable) {
|
if (pmu->selectable) {
|
||||||
scnprintf(buf, sizeof(buf), "%s//", pmu->name);
|
char *s;
|
||||||
aliases[j] = strdup(buf);
|
if (asprintf(&s, "%s//", pmu->name) < 0)
|
||||||
|
goto out_enomem;
|
||||||
|
aliases[j] = s;
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -789,12 +793,20 @@ void print_pmu_events(const char *event_glob, bool name_only)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
printf(" %-50s [Kernel PMU event]\n", aliases[j]);
|
printf(" %-50s [Kernel PMU event]\n", aliases[j]);
|
||||||
zfree(&aliases[j]);
|
|
||||||
printed++;
|
printed++;
|
||||||
}
|
}
|
||||||
if (printed)
|
if (printed)
|
||||||
printf("\n");
|
printf("\n");
|
||||||
free(aliases);
|
out_free:
|
||||||
|
for (j = 0; j < len; j++)
|
||||||
|
zfree(&aliases[j]);
|
||||||
|
zfree(&aliases);
|
||||||
|
return;
|
||||||
|
|
||||||
|
out_enomem:
|
||||||
|
printf("FATAL: not enough memory to print PMU events\n");
|
||||||
|
if (aliases)
|
||||||
|
goto out_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pmu_have_event(const char *pname, const char *name)
|
bool pmu_have_event(const char *pname, const char *name)
|
||||||
|
Loading…
Reference in New Issue
Block a user