Skip to content

Commit e62ac39

Browse files
Leo-Yangregkh
authored andcommitted
perf expr: Return -EINVAL for syntax error in expr__find_ids()
[ Upstream commit 3a61fd8 ] expr__find_ids() propagates the parser return value directly. For syntax errors, the parser can return a positive value, but callers treat it as success, e.g., for below case on Arm64 platform: metric expr 100 * (STALL_SLOT_BACKEND / (CPU_CYCLES * #slots) - BR_MIS_PRED * 3 / CPU_CYCLES) for backend_bound parsing metric: 100 * (STALL_SLOT_BACKEND / (CPU_CYCLES * #slots) - BR_MIS_PRED * 3 / CPU_CYCLES) Failure to read '#slots' literal: #slots = nan syntax error Convert positive parser returns in expr__find_ids() to -EINVAL, as a result, the error value will be respected by callers. Before: perf stat -C 5 Failure to read '#slots'Failure to read '#slots'Failure to read '#slots'Failure to read '#slots'Segmentation fault After: perf stat -C 5 Failure to read '#slots'Cannot find metric or group `Default' Fixes: ded80bd ("perf expr: Migrate expr ids table to a hashmap") Signed-off-by: Leo Yan <leo.yan@arm.com> Reviewed-by: Ian Rogers <irogers@google.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 131e9cb commit e62ac39

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

tools/perf/util/expr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ int expr__find_ids(const char *expr, const char *one,
376376
if (one)
377377
expr__del_id(ctx, one);
378378

379-
return ret;
379+
/* A positive value means syntax error, convert to -EINVAL */
380+
return ret > 0 ? -EINVAL : ret;
380381
}
381382

382383
double expr_id_data__value(const struct expr_id_data *data)

0 commit comments

Comments
 (0)