diff options
author | Masami Hiramatsu <mhiramat@kernel.org> | 2016-05-10 01:47:44 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-05-10 10:57:52 -0400 |
commit | 11db4e29bb50442ecef2173f325b7be4e7790025 (patch) | |
tree | 696636577cb3733f7ecbdc4c9bdba4de47f05df5 /tools/perf | |
parent | 642aadaa320bf9466fd12e3c0903977410bcb731 (diff) |
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>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/util/pmu.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index bf34468a99cb..ddb0261b2577 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c | |||
@@ -643,20 +643,20 @@ static int pmu_resolve_param_term(struct parse_events_term *term, | |||
643 | static char *pmu_formats_string(struct list_head *formats) | 643 | static char *pmu_formats_string(struct list_head *formats) |
644 | { | 644 | { |
645 | struct perf_pmu_format *format; | 645 | struct perf_pmu_format *format; |
646 | char *str; | 646 | char *str = NULL; |
647 | struct strbuf buf; | 647 | struct strbuf buf = STRBUF_INIT; |
648 | unsigned i = 0; | 648 | unsigned i = 0; |
649 | 649 | ||
650 | if (!formats) | 650 | if (!formats) |
651 | return NULL; | 651 | return NULL; |
652 | 652 | ||
653 | strbuf_init(&buf, 0); | ||
654 | /* sysfs exported terms */ | 653 | /* sysfs exported terms */ |
655 | list_for_each_entry(format, formats, list) | 654 | list_for_each_entry(format, formats, list) |
656 | strbuf_addf(&buf, i++ ? ",%s" : "%s", | 655 | if (strbuf_addf(&buf, i++ ? ",%s" : "%s", format->name) < 0) |
657 | format->name); | 656 | goto error; |
658 | 657 | ||
659 | str = strbuf_detach(&buf, NULL); | 658 | str = strbuf_detach(&buf, NULL); |
659 | error: | ||
660 | strbuf_release(&buf); | 660 | strbuf_release(&buf); |
661 | 661 | ||
662 | return str; | 662 | return str; |