From: Masami Hiramatsu Date: Tue, 10 May 2016 05:47:44 +0000 (+0900) Subject: perf pmu: Make pmu_formats_string to check return value of strbuf X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=11db4e29bb50442ecef2173f325b7be4e7790025;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git 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 Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/20160510054744.6158.37810.stgit@devbox Signed-off-by: Arnaldo Carvalho de Melo --- 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, static char *pmu_formats_string(struct list_head *formats) { struct perf_pmu_format *format; - char *str; - struct strbuf buf; + char *str = NULL; + struct strbuf buf = STRBUF_INIT; unsigned i = 0; if (!formats) return NULL; - strbuf_init(&buf, 0); /* sysfs exported terms */ list_for_each_entry(format, formats, list) - strbuf_addf(&buf, i++ ? ",%s" : "%s", - format->name); + if (strbuf_addf(&buf, i++ ? ",%s" : "%s", format->name) < 0) + goto error; str = strbuf_detach(&buf, NULL); +error: strbuf_release(&buf); return str;