Commit a26e4716 authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo

perf tools: Move ALLOC_LIST into a function

Having a YYABORT in a macro makes it hard to free memory for components
of a rule. Separate the logic out.
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Acked-by: default avatarJiri 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/20191023005337.196160-5-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 2ccfb8bc
...@@ -25,12 +25,17 @@ do { \ ...@@ -25,12 +25,17 @@ do { \
YYABORT; \ YYABORT; \
} while (0) } while (0)
#define ALLOC_LIST(list) \ static struct list_head* alloc_list()
do { \ {
list = malloc(sizeof(*list)); \ struct list_head *list;
ABORT_ON(!list); \
INIT_LIST_HEAD(list); \ list = malloc(sizeof(*list));
} while (0) if (!list)
return NULL;
INIT_LIST_HEAD(list);
return list;
}
static void inc_group_count(struct list_head *list, static void inc_group_count(struct list_head *list,
struct parse_events_state *parse_state) struct parse_events_state *parse_state)
...@@ -238,7 +243,8 @@ PE_NAME opt_pmu_config ...@@ -238,7 +243,8 @@ PE_NAME opt_pmu_config
if (error) if (error)
error->idx = @1.first_column; error->idx = @1.first_column;
ALLOC_LIST(list); list = alloc_list();
ABORT_ON(!list);
if (parse_events_add_pmu(_parse_state, list, $1, $2, false, false)) { if (parse_events_add_pmu(_parse_state, list, $1, $2, false, false)) {
struct perf_pmu *pmu = NULL; struct perf_pmu *pmu = NULL;
int ok = 0; int ok = 0;
...@@ -306,7 +312,8 @@ value_sym '/' event_config '/' ...@@ -306,7 +312,8 @@ value_sym '/' event_config '/'
int type = $1 >> 16; int type = $1 >> 16;
int config = $1 & 255; int config = $1 & 255;
ALLOC_LIST(list); list = alloc_list();
ABORT_ON(!list);
ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, $3)); ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, $3));
parse_events_terms__delete($3); parse_events_terms__delete($3);
$$ = list; $$ = list;
...@@ -318,7 +325,8 @@ value_sym sep_slash_slash_dc ...@@ -318,7 +325,8 @@ value_sym sep_slash_slash_dc
int type = $1 >> 16; int type = $1 >> 16;
int config = $1 & 255; int config = $1 & 255;
ALLOC_LIST(list); list = alloc_list();
ABORT_ON(!list);
ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, NULL)); ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, NULL));
$$ = list; $$ = list;
} }
...@@ -327,7 +335,8 @@ PE_VALUE_SYM_TOOL sep_slash_slash_dc ...@@ -327,7 +335,8 @@ PE_VALUE_SYM_TOOL sep_slash_slash_dc
{ {
struct list_head *list; struct list_head *list;
ALLOC_LIST(list); list = alloc_list();
ABORT_ON(!list);
ABORT_ON(parse_events_add_tool(_parse_state, list, $1)); ABORT_ON(parse_events_add_tool(_parse_state, list, $1));
$$ = list; $$ = list;
} }
...@@ -339,7 +348,8 @@ PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT opt_e ...@@ -339,7 +348,8 @@ PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT opt_e
struct parse_events_error *error = parse_state->error; struct parse_events_error *error = parse_state->error;
struct list_head *list; struct list_head *list;
ALLOC_LIST(list); list = alloc_list();
ABORT_ON(!list);
ABORT_ON(parse_events_add_cache(list, &parse_state->idx, $1, $3, $5, error, $6)); ABORT_ON(parse_events_add_cache(list, &parse_state->idx, $1, $3, $5, error, $6));
parse_events_terms__delete($6); parse_events_terms__delete($6);
$$ = list; $$ = list;
...@@ -351,7 +361,8 @@ PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT opt_event_config ...@@ -351,7 +361,8 @@ PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT opt_event_config
struct parse_events_error *error = parse_state->error; struct parse_events_error *error = parse_state->error;
struct list_head *list; struct list_head *list;
ALLOC_LIST(list); list = alloc_list();
ABORT_ON(!list);
ABORT_ON(parse_events_add_cache(list, &parse_state->idx, $1, $3, NULL, error, $4)); ABORT_ON(parse_events_add_cache(list, &parse_state->idx, $1, $3, NULL, error, $4));
parse_events_terms__delete($4); parse_events_terms__delete($4);
$$ = list; $$ = list;
...@@ -363,7 +374,8 @@ PE_NAME_CACHE_TYPE opt_event_config ...@@ -363,7 +374,8 @@ PE_NAME_CACHE_TYPE opt_event_config
struct parse_events_error *error = parse_state->error; struct parse_events_error *error = parse_state->error;
struct list_head *list; struct list_head *list;
ALLOC_LIST(list); list = alloc_list();
ABORT_ON(!list);
ABORT_ON(parse_events_add_cache(list, &parse_state->idx, $1, NULL, NULL, error, $2)); ABORT_ON(parse_events_add_cache(list, &parse_state->idx, $1, NULL, NULL, error, $2));
parse_events_terms__delete($2); parse_events_terms__delete($2);
$$ = list; $$ = list;
...@@ -375,7 +387,8 @@ PE_PREFIX_MEM PE_VALUE '/' PE_VALUE ':' PE_MODIFIER_BP sep_dc ...@@ -375,7 +387,8 @@ PE_PREFIX_MEM PE_VALUE '/' PE_VALUE ':' PE_MODIFIER_BP sep_dc
struct parse_events_state *parse_state = _parse_state; struct parse_events_state *parse_state = _parse_state;
struct list_head *list; struct list_head *list;
ALLOC_LIST(list); list = alloc_list();
ABORT_ON(!list);
ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx, ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx,
(void *) $2, $6, $4)); (void *) $2, $6, $4));
$$ = list; $$ = list;
...@@ -386,7 +399,8 @@ PE_PREFIX_MEM PE_VALUE '/' PE_VALUE sep_dc ...@@ -386,7 +399,8 @@ PE_PREFIX_MEM PE_VALUE '/' PE_VALUE sep_dc
struct parse_events_state *parse_state = _parse_state; struct parse_events_state *parse_state = _parse_state;
struct list_head *list; struct list_head *list;
ALLOC_LIST(list); list = alloc_list();
ABORT_ON(!list);
ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx, ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx,
(void *) $2, NULL, $4)); (void *) $2, NULL, $4));
$$ = list; $$ = list;
...@@ -397,7 +411,8 @@ PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc ...@@ -397,7 +411,8 @@ PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
struct parse_events_state *parse_state = _parse_state; struct parse_events_state *parse_state = _parse_state;
struct list_head *list; struct list_head *list;
ALLOC_LIST(list); list = alloc_list();
ABORT_ON(!list);
ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx, ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx,
(void *) $2, $4, 0)); (void *) $2, $4, 0));
$$ = list; $$ = list;
...@@ -408,7 +423,8 @@ PE_PREFIX_MEM PE_VALUE sep_dc ...@@ -408,7 +423,8 @@ PE_PREFIX_MEM PE_VALUE sep_dc
struct parse_events_state *parse_state = _parse_state; struct parse_events_state *parse_state = _parse_state;
struct list_head *list; struct list_head *list;
ALLOC_LIST(list); list = alloc_list();
ABORT_ON(!list);
ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx, ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx,
(void *) $2, NULL, 0)); (void *) $2, NULL, 0));
$$ = list; $$ = list;
...@@ -421,7 +437,8 @@ tracepoint_name opt_event_config ...@@ -421,7 +437,8 @@ tracepoint_name opt_event_config
struct parse_events_error *error = parse_state->error; struct parse_events_error *error = parse_state->error;
struct list_head *list; struct list_head *list;
ALLOC_LIST(list); list = alloc_list();
ABORT_ON(!list);
if (error) if (error)
error->idx = @1.first_column; error->idx = @1.first_column;
...@@ -457,7 +474,8 @@ PE_VALUE ':' PE_VALUE opt_event_config ...@@ -457,7 +474,8 @@ PE_VALUE ':' PE_VALUE opt_event_config
{ {
struct list_head *list; struct list_head *list;
ALLOC_LIST(list); list = alloc_list();
ABORT_ON(!list);
ABORT_ON(parse_events_add_numeric(_parse_state, list, (u32)$1, $3, $4)); ABORT_ON(parse_events_add_numeric(_parse_state, list, (u32)$1, $3, $4));
parse_events_terms__delete($4); parse_events_terms__delete($4);
$$ = list; $$ = list;
...@@ -468,7 +486,8 @@ PE_RAW opt_event_config ...@@ -468,7 +486,8 @@ PE_RAW opt_event_config
{ {
struct list_head *list; struct list_head *list;
ALLOC_LIST(list); list = alloc_list();
ABORT_ON(!list);
ABORT_ON(parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, $1, $2)); ABORT_ON(parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, $1, $2));
parse_events_terms__delete($2); parse_events_terms__delete($2);
$$ = list; $$ = list;
...@@ -480,7 +499,8 @@ PE_BPF_OBJECT opt_event_config ...@@ -480,7 +499,8 @@ PE_BPF_OBJECT opt_event_config
struct parse_events_state *parse_state = _parse_state; struct parse_events_state *parse_state = _parse_state;
struct list_head *list; struct list_head *list;
ALLOC_LIST(list); list = alloc_list();
ABORT_ON(!list);
ABORT_ON(parse_events_load_bpf(parse_state, list, $1, false, $2)); ABORT_ON(parse_events_load_bpf(parse_state, list, $1, false, $2));
parse_events_terms__delete($2); parse_events_terms__delete($2);
$$ = list; $$ = list;
...@@ -490,7 +510,8 @@ PE_BPF_SOURCE opt_event_config ...@@ -490,7 +510,8 @@ PE_BPF_SOURCE opt_event_config
{ {
struct list_head *list; struct list_head *list;
ALLOC_LIST(list); list = alloc_list();
ABORT_ON(!list);
ABORT_ON(parse_events_load_bpf(_parse_state, list, $1, true, $2)); ABORT_ON(parse_events_load_bpf(_parse_state, list, $1, true, $2));
parse_events_terms__delete($2); parse_events_terms__delete($2);
$$ = list; $$ = list;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment