perf pmu: Make pmu_formats_string to check return value of strbuf

Make pmu_formats_string() to check return value of strbuf APIs so that
it can detect errors in it.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20160510054744.6158.37810.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Masami Hiramatsu 2016-05-10 14:47:44 +09:00 committed by Arnaldo Carvalho de Melo
parent 642aadaa32
commit 11db4e29bb
1 changed files with 5 additions and 5 deletions

View File

@ -643,20 +643,20 @@ static int pmu_resolve_param_term(struct parse_events_term *term,
static char *pmu_formats_string(struct list_head *formats) static char *pmu_formats_string(struct list_head *formats)
{ {
struct perf_pmu_format *format; struct perf_pmu_format *format;
char *str; char *str = NULL;
struct strbuf buf; struct strbuf buf = STRBUF_INIT;
unsigned i = 0; unsigned i = 0;
if (!formats) if (!formats)
return NULL; return NULL;
strbuf_init(&buf, 0);
/* sysfs exported terms */ /* sysfs exported terms */
list_for_each_entry(format, formats, list) list_for_each_entry(format, formats, list)
strbuf_addf(&buf, i++ ? ",%s" : "%s", if (strbuf_addf(&buf, i++ ? ",%s" : "%s", format->name) < 0)
format->name); goto error;
str = strbuf_detach(&buf, NULL); str = strbuf_detach(&buf, NULL);
error:
strbuf_release(&buf); strbuf_release(&buf);
return str; return str;