diff options
author | Adrian Hunter <adrian.hunter@intel.com> | 2022-08-09 11:07:02 +0300 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2022-08-10 20:30:09 +0300 |
commit | 806731a9465b42aaf887cbaf8bfee7eccc9417de (patch) | |
tree | 7a1cf71e17d762a0f7dffd5c473b999d20147ff6 /tools/perf/util | |
parent | 1da1d60774014137d776d0400fdf2f1779d8d4d5 (diff) | |
download | linux-806731a9465b42aaf887cbaf8bfee7eccc9417de.tar.xz |
perf tools: Do not pass NULL to parse_events()
Many cases do not use the extra error information provided by
parse_events and instead pass NULL as the struct parse_events_error
pointer. Add a wrapper for those cases so that the pointer is never
NULL.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20220809080702.6921-4-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util')
-rw-r--r-- | tools/perf/util/bpf-loader.c | 2 | ||||
-rw-r--r-- | tools/perf/util/parse-events.c | 18 | ||||
-rw-r--r-- | tools/perf/util/parse-events.h | 4 | ||||
-rw-r--r-- | tools/perf/util/perf_api_probe.c | 2 | ||||
-rw-r--r-- | tools/perf/util/record.c | 2 |
5 files changed, 19 insertions, 9 deletions
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index d2c9b09ddb48..e2052f4fed33 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -1879,7 +1879,7 @@ struct evsel *bpf__setup_output_event(struct evlist *evlist, const char *name) if (asprintf(&event_definition, "bpf-output/no-inherit=1,name=%s/", name) < 0) return ERR_PTR(-ENOMEM); - err = parse_events(evlist, event_definition, NULL); + err = parse_event(evlist, event_definition); free(event_definition); if (err) { diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index dfc7d7a0ec4e..f05e15acd33f 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -2240,6 +2240,17 @@ int __parse_events(struct evlist *evlist, const char *str, return ret; } +int parse_event(struct evlist *evlist, const char *str) +{ + struct parse_events_error err; + int ret; + + parse_events_error__init(&err); + ret = parse_events(evlist, str, &err); + parse_events_error__exit(&err); + return ret; +} + void parse_events_error__init(struct parse_events_error *err) { bzero(err, sizeof(*err)); @@ -2256,13 +2267,8 @@ void parse_events_error__exit(struct parse_events_error *err) void parse_events_error__handle(struct parse_events_error *err, int idx, char *str, char *help) { - if (WARN(!str, "WARNING: failed to provide error string\n")) - goto out_free; - if (!err) { - /* Assume caller does not want message printed */ - pr_debug("event syntax error: %s\n", str); + if (WARN(!str || !err, "WARNING: failed to provide error string or struct\n")) goto out_free; - } switch (err->num_errors) { case 0: err->idx = idx; diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index ba9fa3ddaf6e..7e6a601d9cd0 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -24,15 +24,19 @@ const char *event_type(int type); int parse_events_option(const struct option *opt, const char *str, int unset); int parse_events_option_new_evlist(const struct option *opt, const char *str, int unset); +__attribute__((nonnull(1, 2, 3))) int __parse_events(struct evlist *evlist, const char *str, struct parse_events_error *error, struct perf_pmu *fake_pmu); +__attribute__((nonnull)) static inline int parse_events(struct evlist *evlist, const char *str, struct parse_events_error *err) { return __parse_events(evlist, str, err, NULL); } +int parse_event(struct evlist *evlist, const char *str); + int parse_events_terms(struct list_head *terms, const char *str); int parse_filter(const struct option *opt, const char *str, int unset); int exclude_perf(const struct option *opt, const char *arg, int unset); diff --git a/tools/perf/util/perf_api_probe.c b/tools/perf/util/perf_api_probe.c index c28dd50bd571..e1e2d701599c 100644 --- a/tools/perf/util/perf_api_probe.c +++ b/tools/perf/util/perf_api_probe.c @@ -23,7 +23,7 @@ static int perf_do_probe_api(setup_probe_fn_t fn, struct perf_cpu cpu, const cha if (!evlist) return -ENOMEM; - if (parse_events(evlist, str, NULL)) + if (parse_event(evlist, str)) goto out_delete; evsel = evlist__first(evlist); diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c index b529636ab3ea..7b58f6c7c69d 100644 --- a/tools/perf/util/record.c +++ b/tools/perf/util/record.c @@ -238,7 +238,7 @@ bool evlist__can_select_event(struct evlist *evlist, const char *str) if (!temp_evlist) return false; - err = parse_events(temp_evlist, str, NULL); + err = parse_event(temp_evlist, str); if (err) goto out_delete; |