bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "tip-bot2 for Ian Rogers" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Ian Rogers <irogers@google.com>, Jiri Olsa <jolsa@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Andi Kleen <ak@linux.intel.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jin Yao <yao.jin@linux.intel.com>,
	John Garry <john.garry@huawei.com>,
	Kan Liang <kan.liang@linux.intel.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Martin KaFai Lau <kafai@fb.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Song Liu <songliubraving@fb.com>,
	Stephane Eranian <eranian@google.com>, Yonghong Song <yhs@fb.com>,
	bpf@vger.kernel.org, clang-built-linux@googlegroups.com,
	netdev@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Ingo Molnar <mingo@kernel.org>, Borislav Petkov <bp@alien8.de>,
	linux-kernel@vger.kernel.org
Subject: [tip: perf/core] perf parse: Ensure config and str in terms are unique
Date: Tue, 12 Nov 2019 11:17:57 -0000	[thread overview]
Message-ID: <157355747780.29376.16809471033952715746.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20191030223448.12930-6-irogers@google.com>

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     b6645a72359590ad7f57050d192cd5d8885320df
Gitweb:        https://git.kernel.org/tip/b6645a72359590ad7f57050d192cd5d8885320df
Author:        Ian Rogers <irogers@google.com>
AuthorDate:    Wed, 30 Oct 2019 15:34:43 -07:00
Committer:     Arnaldo Carvalho de Melo <acme@redhat.com>
CommitterDate: Wed, 06 Nov 2019 15:49:40 -03:00

perf parse: Ensure config and str in terms are unique

Make it easier to release memory associated with parse event terms by
duplicating the string for the config name and ensuring the val string
is a duplicate.

Currently the parser may memory leak terms and this is addressed in a
later patch.

Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Martin KaFai Lau <kafai@fb.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Yonghong Song <yhs@fb.com>
Cc: bpf@vger.kernel.org
Cc: clang-built-linux@googlegroups.com
Cc: netdev@vger.kernel.org
Link: http://lore.kernel.org/lkml/20191030223448.12930-6-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/parse-events.c | 51 +++++++++++++++++++++++++++------
 tools/perf/util/parse-events.y |  4 ++-
 2 files changed, 45 insertions(+), 10 deletions(-)

diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 03e54a2..578288c 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -1412,7 +1412,6 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,
 int parse_events_multi_pmu_add(struct parse_events_state *parse_state,
 			       char *str, struct list_head **listp)
 {
-	struct list_head *head;
 	struct parse_events_term *term;
 	struct list_head *list;
 	struct perf_pmu *pmu = NULL;
@@ -1429,19 +1428,30 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state,
 
 		list_for_each_entry(alias, &pmu->aliases, list) {
 			if (!strcasecmp(alias->name, str)) {
+				struct list_head *head;
+				char *config;
+
 				head = malloc(sizeof(struct list_head));
 				if (!head)
 					return -1;
 				INIT_LIST_HEAD(head);
-				if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
-							   str, 1, false, &str, NULL) < 0)
+				config = strdup(str);
+				if (!config)
+					return -1;
+				if (parse_events_term__num(&term,
+						   PARSE_EVENTS__TERM_TYPE_USER,
+						   config, 1, false, &config,
+						   NULL) < 0) {
+					free(list);
+					free(config);
 					return -1;
+				}
 				list_add_tail(&term->list, head);
 
 				if (!parse_events_add_pmu(parse_state, list,
 							  pmu->name, head,
 							  true, true)) {
-					pr_debug("%s -> %s/%s/\n", str,
+					pr_debug("%s -> %s/%s/\n", config,
 						 pmu->name, alias->str);
 					ok++;
 				}
@@ -1450,8 +1460,10 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state,
 			}
 		}
 	}
-	if (!ok)
+	if (!ok) {
+		free(list);
 		return -1;
+	}
 	*listp = list;
 	return 0;
 }
@@ -2746,30 +2758,51 @@ int parse_events_term__sym_hw(struct parse_events_term **term,
 			      char *config, unsigned idx)
 {
 	struct event_symbol *sym;
+	char *str;
 	struct parse_events_term temp = {
 		.type_val  = PARSE_EVENTS__TERM_TYPE_STR,
 		.type_term = PARSE_EVENTS__TERM_TYPE_USER,
-		.config    = config ?: (char *) "event",
+		.config    = config,
 	};
 
+	if (!temp.config) {
+		temp.config = strdup("event");
+		if (!temp.config)
+			return -ENOMEM;
+	}
 	BUG_ON(idx >= PERF_COUNT_HW_MAX);
 	sym = &event_symbols_hw[idx];
 
-	return new_term(term, &temp, (char *) sym->symbol, 0);
+	str = strdup(sym->symbol);
+	if (!str)
+		return -ENOMEM;
+	return new_term(term, &temp, str, 0);
 }
 
 int parse_events_term__clone(struct parse_events_term **new,
 			     struct parse_events_term *term)
 {
+	char *str;
 	struct parse_events_term temp = {
 		.type_val  = term->type_val,
 		.type_term = term->type_term,
-		.config    = term->config,
+		.config    = NULL,
 		.err_term  = term->err_term,
 		.err_val   = term->err_val,
 	};
 
-	return new_term(new, &temp, term->val.str, term->val.num);
+	if (term->config) {
+		temp.config = strdup(term->config);
+		if (!temp.config)
+			return -ENOMEM;
+	}
+	if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM)
+		return new_term(new, &temp, NULL, term->val.num);
+
+	str = strdup(term->val.str);
+	if (!str)
+		return -ENOMEM;
+	return new_term(new, &temp, str, 0);
 }
 
 int parse_events_copy_term_list(struct list_head *old,
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index ffa1a1b..545ab7c 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -665,9 +665,11 @@ PE_NAME array '=' PE_VALUE
 PE_DRV_CFG_TERM
 {
 	struct parse_events_term *term;
+	char *config = strdup($1);
 
+	ABORT_ON(!config);
 	ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG,
-					$1, $1, &@1, NULL));
+					config, $1, &@1, NULL));
 	$$ = term;
 }
 

  parent reply	other threads:[~2019-11-12 11:20 UTC|newest]

Thread overview: 101+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20191017170531.171244-1-irogers@google.com>
2019-10-23  0:53 ` [PATCH v2 0/9] Improvements to memory usage by parse events Ian Rogers
2019-10-23  0:53   ` [PATCH v2 1/9] perf tools: add parse events append error Ian Rogers
2019-10-23  8:36     ` Jiri Olsa
2019-10-23  0:53   ` [PATCH v2 2/9] perf tools: splice events onto evlist even on error Ian Rogers
2019-10-23  8:40     ` Jiri Olsa
2019-10-23  0:53   ` [PATCH v2 3/9] perf tools: ensure config and str in terms are unique Ian Rogers
2019-10-23  8:50     ` Jiri Olsa
2019-10-23  0:53   ` [PATCH v2 4/9] perf tools: move ALLOC_LIST into a function Ian Rogers
2019-10-23  8:55     ` Jiri Olsa
2019-10-23 12:37       ` Arnaldo Carvalho de Melo
2019-11-12 11:18     ` [tip: perf/core] perf tools: Move " tip-bot2 for Ian Rogers
2019-10-23  0:53   ` [PATCH v2 5/9] perf tools: avoid a malloc for array events Ian Rogers
2019-10-23  8:58     ` Jiri Olsa
2019-10-23 12:38       ` Arnaldo Carvalho de Melo
2019-11-12 11:18     ` [tip: perf/core] perf tools: Avoid a malloc() " tip-bot2 for Ian Rogers
2019-10-23  0:53   ` [PATCH v2 6/9] perf tools: add destructors for parse event terms Ian Rogers
2019-10-23  9:01     ` Jiri Olsa
2019-10-24 19:03       ` Ian Rogers
2019-10-23  0:53   ` [PATCH v2 7/9] perf tools: before yyabort-ing free components Ian Rogers
2019-10-23  0:53   ` [PATCH v2 8/9] perf tools: if pmu configuration fails free terms Ian Rogers
2019-10-23  0:53   ` [PATCH v2 9/9] perf tools: add a deep delete for parse event terms Ian Rogers
2019-10-24 19:01   ` [PATCH v3 0/9] Improvements to memory usage by parse events Ian Rogers
2019-10-24 19:01     ` [PATCH v3 1/9] perf tools: add parse events append error Ian Rogers
2019-10-25  7:58       ` Jiri Olsa
2019-10-25 15:14         ` Ian Rogers
2019-10-28 19:32           ` Jiri Olsa
2019-10-28 21:06             ` Ian Rogers
2019-10-28 21:36               ` Jiri Olsa
2019-11-04 20:37                 ` Ian Rogers
2019-10-24 19:01     ` [PATCH v3 2/9] perf tools: splice events onto evlist even on error Ian Rogers
2019-10-25  8:01       ` Jiri Olsa
2019-10-25 15:47         ` Ian Rogers
2019-10-28 21:06           ` Jiri Olsa
2019-10-24 19:01     ` [PATCH v3 3/9] perf tools: ensure config and str in terms are unique Ian Rogers
2019-10-25  8:10       ` Jiri Olsa
2019-10-25 15:52         ` Ian Rogers
2019-10-24 19:01     ` [PATCH v3 4/9] perf tools: move ALLOC_LIST into a function Ian Rogers
2019-10-24 19:01     ` [PATCH v3 5/9] perf tools: avoid a malloc for array events Ian Rogers
2019-10-24 19:01     ` [PATCH v3 6/9] perf tools: add destructors for parse event terms Ian Rogers
2019-10-25  8:27       ` Jiri Olsa
2019-10-25 16:08         ` Ian Rogers
2019-10-28 19:33           ` Jiri Olsa
2019-10-24 19:02     ` [PATCH v3 7/9] perf tools: before yyabort-ing free components Ian Rogers
2019-10-24 19:02     ` [PATCH v3 8/9] perf tools: if pmu configuration fails free terms Ian Rogers
2019-10-24 19:02     ` [PATCH v3 9/9] perf tools: add a deep delete for parse event terms Ian Rogers
2019-10-25 18:08     ` [PATCH v4 0/9] Improvements to memory usage by parse events Ian Rogers
2019-10-25 18:08       ` [PATCH v4 1/9] perf tools: add parse events handle error Ian Rogers
2019-10-25 18:08       ` [PATCH v4 2/9] perf tools: move ALLOC_LIST into a function Ian Rogers
2019-10-25 18:08       ` [PATCH v4 3/9] perf tools: avoid a malloc for array events Ian Rogers
2019-10-25 18:08       ` [PATCH v4 4/9] perf tools: splice events onto evlist even on error Ian Rogers
2019-10-28 21:07         ` Jiri Olsa
2019-10-30 11:56           ` Arnaldo Carvalho de Melo
2019-11-12 11:18         ` [tip: perf/core] perf tools: Splice " tip-bot2 for Ian Rogers
2019-10-25 18:08       ` [PATCH v4 5/9] perf tools: ensure config and str in terms are unique Ian Rogers
2019-10-25 18:08       ` [PATCH v4 6/9] perf tools: add destructors for parse event terms Ian Rogers
2019-10-25 18:08       ` [PATCH v4 7/9] perf tools: before yyabort-ing free components Ian Rogers
2019-10-25 18:08       ` [PATCH v4 8/9] perf tools: if pmu configuration fails free terms Ian Rogers
2019-10-25 18:08       ` [PATCH v4 9/9] perf tools: add a deep delete for parse event terms Ian Rogers
2019-10-30 22:34       ` [PATCH v5 00/10] Improvements to memory usage by parse events Ian Rogers
2019-10-30 22:34         ` [PATCH v5 01/10] perf tools: add parse events handle error Ian Rogers
2019-11-06 14:06           ` Jiri Olsa
2019-11-06 14:29             ` Arnaldo Carvalho de Melo
2019-11-12 11:17           ` [tip: perf/core] perf parse: Add " tip-bot2 for Ian Rogers
2019-10-30 22:34         ` [PATCH v5 02/10] perf tools: move ALLOC_LIST into a function Ian Rogers
2019-10-30 22:34         ` [PATCH v5 03/10] perf tools: avoid a malloc for array events Ian Rogers
2019-10-30 22:34         ` [PATCH v5 04/10] perf tools: splice events onto evlist even on error Ian Rogers
2019-10-30 22:34         ` [PATCH v5 05/10] perf tools: ensure config and str in terms are unique Ian Rogers
2019-11-06 14:25           ` Jiri Olsa
2019-11-06 14:31             ` Arnaldo Carvalho de Melo
2019-11-12 11:17           ` tip-bot2 for Ian Rogers [this message]
2019-10-30 22:34         ` [PATCH v5 06/10] perf tools: add destructors for parse event terms Ian Rogers
2019-11-06 14:24           ` Jiri Olsa
2019-11-06 14:35             ` Arnaldo Carvalho de Melo
2019-11-12 11:17           ` [tip: perf/core] perf parse: Add " tip-bot2 for Ian Rogers
2019-10-30 22:34         ` [PATCH v5 07/10] perf tools: before yyabort-ing free components Ian Rogers
2019-11-06 14:24           ` Jiri Olsa
2019-11-06 14:37             ` Arnaldo Carvalho de Melo
2019-11-12 11:17           ` [tip: perf/core] perf parse: Before " tip-bot2 for Ian Rogers
2019-10-30 22:34         ` [PATCH v5 08/10] perf tools: if pmu configuration fails free terms Ian Rogers
2019-11-06 14:24           ` Jiri Olsa
2019-11-06 14:38             ` Arnaldo Carvalho de Melo
2019-11-12 11:17           ` [tip: perf/core] perf parse: If " tip-bot2 for Ian Rogers
2019-10-30 22:34         ` [PATCH v5 09/10] perf tools: add a deep delete for parse event terms Ian Rogers
2019-11-06 14:24           ` Jiri Olsa
2019-11-06 14:39             ` Arnaldo Carvalho de Melo
2019-11-12 11:17           ` [tip: perf/core] perf parse: Add " tip-bot2 for Ian Rogers
2019-10-30 22:34         ` [PATCH v5 10/10] perf tools: report initial event parsing error Ian Rogers
2019-11-06 14:24           ` Jiri Olsa
2019-11-07 22:14         ` [PATCH v6 00/10] Improvements to memory usage by parse events Ian Rogers
2019-11-07 22:14           ` [PATCH v6 01/10] perf tools: add parse events handle error Ian Rogers
2019-11-07 22:14           ` [PATCH v6 02/10] perf tools: move ALLOC_LIST into a function Ian Rogers
2019-11-07 22:14           ` [PATCH v6 03/10] perf tools: avoid a malloc for array events Ian Rogers
2019-11-07 22:14           ` [PATCH v6 04/10] perf tools: splice events onto evlist even on error Ian Rogers
2019-11-07 22:14           ` [PATCH v6 05/10] perf tools: ensure config and str in terms are unique Ian Rogers
2019-11-07 22:14           ` [PATCH v6 06/10] perf tools: add destructors for parse event terms Ian Rogers
2019-11-07 22:14           ` [PATCH v6 07/10] perf tools: before yyabort-ing free components Ian Rogers
2019-11-07 22:14           ` [PATCH v6 08/10] perf tools: if pmu configuration fails free terms Ian Rogers
2019-11-07 22:14           ` [PATCH v6 09/10] perf tools: add a deep delete for parse event terms Ian Rogers
2019-11-07 22:14           ` [PATCH v6 10/10] perf tools: report initial event parsing error Ian Rogers
2019-11-07 22:23           ` [PATCH v6 00/10] Improvements to memory usage by parse events Arnaldo Carvalho de Melo
2019-11-08 18:18             ` Ian Rogers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=157355747780.29376.16809471033952715746.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=ast@kernel.org \
    --cc=bp@alien8.de \
    --cc=bpf@vger.kernel.org \
    --cc=clang-built-linux@googlegroups.com \
    --cc=daniel@iogearbox.net \
    --cc=eranian@google.com \
    --cc=irogers@google.com \
    --cc=john.garry@huawei.com \
    --cc=jolsa@kernel.org \
    --cc=kafai@fb.com \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=songliubraving@fb.com \
    --cc=yao.jin@linux.intel.com \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).