Skip to content

Commit

Permalink
perf parse-events: Move instances of YYABORT to YYNOMEM
Browse files Browse the repository at this point in the history
Migration to improve error reporting as YYABORT cases should carry
event parsing errors.

Signed-off-by: Ian Rogers <[email protected]>
Cc: Adrian Hunter <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Athira Rajeev <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Kan Liang <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: [email protected]
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
captain5050 authored and acmel committed Jul 28, 2023
1 parent a7a3252 commit 77cdd78
Showing 1 changed file with 40 additions and 18 deletions.
58 changes: 40 additions & 18 deletions tools/perf/util/parse-events.y
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,8 @@ value_sym '/' event_config '/'
bool wildcard = (type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE);

list = alloc_list();
ABORT_ON(!list);
if (!list)
YYNOMEM;
err = parse_events_add_numeric(_parse_state, list, type, config, $3, wildcard);
parse_events_terms__delete($3);
if (err) {
Expand All @@ -408,7 +409,8 @@ value_sym sep_slash_slash_dc
bool wildcard = (type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE);

list = alloc_list();
ABORT_ON(!list);
if (!list)
YYNOMEM;
ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config,
/*head_config=*/NULL, wildcard));
$$ = list;
Expand All @@ -419,7 +421,8 @@ PE_VALUE_SYM_TOOL sep_slash_slash_dc
struct list_head *list;

list = alloc_list();
ABORT_ON(!list);
if (!list)
YYNOMEM;
ABORT_ON(parse_events_add_tool(_parse_state, list, $1));
$$ = list;
}
Expand All @@ -432,7 +435,9 @@ PE_LEGACY_CACHE opt_event_config
int err;

list = alloc_list();
ABORT_ON(!list);
if (!list)
YYNOMEM;

err = parse_events_add_cache(list, &parse_state->idx, $1, parse_state, $2);

parse_events_terms__delete($2);
Expand All @@ -451,7 +456,9 @@ PE_PREFIX_MEM PE_VALUE PE_BP_SLASH PE_VALUE PE_BP_COLON PE_MODIFIER_BP opt_event
int err;

list = alloc_list();
ABORT_ON(!list);
if (!list)
YYNOMEM;

err = parse_events_add_breakpoint(_parse_state, list,
$2, $6, $4, $7);
parse_events_terms__delete($7);
Expand All @@ -469,7 +476,9 @@ PE_PREFIX_MEM PE_VALUE PE_BP_SLASH PE_VALUE opt_event_config
int err;

list = alloc_list();
ABORT_ON(!list);
if (!list)
YYNOMEM;

err = parse_events_add_breakpoint(_parse_state, list,
$2, NULL, $4, $5);
parse_events_terms__delete($5);
Expand All @@ -486,7 +495,9 @@ PE_PREFIX_MEM PE_VALUE PE_BP_COLON PE_MODIFIER_BP opt_event_config
int err;

list = alloc_list();
ABORT_ON(!list);
if (!list)
YYNOMEM;

err = parse_events_add_breakpoint(_parse_state, list,
$2, $4, 0, $5);
parse_events_terms__delete($5);
Expand All @@ -504,7 +515,8 @@ PE_PREFIX_MEM PE_VALUE opt_event_config
int err;

list = alloc_list();
ABORT_ON(!list);
if (!list)
YYNOMEM;
err = parse_events_add_breakpoint(_parse_state, list,
$2, NULL, 0, $3);
parse_events_terms__delete($3);
Expand All @@ -524,7 +536,8 @@ tracepoint_name opt_event_config
int err;

list = alloc_list();
ABORT_ON(!list);
if (!list)
YYNOMEM;
if (error)
error->idx = @1.first_column;

Expand Down Expand Up @@ -556,7 +569,8 @@ PE_VALUE ':' PE_VALUE opt_event_config
int err;

list = alloc_list();
ABORT_ON(!list);
if (!list)
YYNOMEM;
err = parse_events_add_numeric(_parse_state, list, (u32)$1, $3, $4,
/*wildcard=*/false);
parse_events_terms__delete($4);
Expand All @@ -575,7 +589,8 @@ PE_RAW opt_event_config
u64 num;

list = alloc_list();
ABORT_ON(!list);
if (!list)
YYNOMEM;
errno = 0;
num = strtoull($1 + 1, NULL, 16);
ABORT_ON(errno);
Expand All @@ -598,7 +613,8 @@ PE_BPF_OBJECT opt_event_config
int err;

list = alloc_list();
ABORT_ON(!list);
if (!list)
YYNOMEM;
err = parse_events_load_bpf(parse_state, list, $1, false, $2);
parse_events_terms__delete($2);
free($1);
Expand All @@ -615,7 +631,8 @@ PE_BPF_SOURCE opt_event_config
int err;

list = alloc_list();
ABORT_ON(!list);
if (!list)
YYNOMEM;
err = parse_events_load_bpf(_parse_state, list, $1, true, $2);
parse_events_terms__delete($2);
if (err) {
Expand Down Expand Up @@ -680,7 +697,8 @@ event_term
struct list_head *head = malloc(sizeof(*head));
struct parse_events_term *term = $1;

ABORT_ON(!head);
if (!head)
YYNOMEM;
INIT_LIST_HEAD(head);
list_add_tail(&term->list, head);
$$ = head;
Expand Down Expand Up @@ -857,7 +875,8 @@ PE_DRV_CFG_TERM
struct parse_events_term *term;
char *config = strdup($1);

ABORT_ON(!config);
if (!config)
YYNOMEM;
if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG,
config, $1, &@1, NULL)) {
free($1);
Expand Down Expand Up @@ -888,7 +907,8 @@ array_terms ',' array_term
new_array.ranges = realloc($1.ranges,
sizeof(new_array.ranges[0]) *
new_array.nr_ranges);
ABORT_ON(!new_array.ranges);
if (!new_array.ranges)
YYNOMEM;
memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges,
$3.nr_ranges * sizeof(new_array.ranges[0]));
free($3.ranges);
Expand All @@ -904,7 +924,8 @@ PE_VALUE

array.nr_ranges = 1;
array.ranges = malloc(sizeof(array.ranges[0]));
ABORT_ON(!array.ranges);
if (!array.ranges)
YYNOMEM;
array.ranges[0].start = $1;
array.ranges[0].length = 1;
$$ = array;
Expand All @@ -917,7 +938,8 @@ PE_VALUE PE_ARRAY_RANGE PE_VALUE
ABORT_ON($3 < $1);
array.nr_ranges = 1;
array.ranges = malloc(sizeof(array.ranges[0]));
ABORT_ON(!array.ranges);
if (!array.ranges)
YYNOMEM;
array.ranges[0].start = $1;
array.ranges[0].length = $3 - $1 + 1;
$$ = array;
Expand Down

0 comments on commit 77cdd78

Please sign in to comment.