From 99e7138eb7897aa0ccc6661173ae2d7e79721e05 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Fri, 17 Feb 2017 15:00:56 +0100 Subject: perf tools: Fail on using multiple bits long terms without value Currently we allow not to specify value for numeric terms and we set them to value 1. This was originaly meant just for single bit terms to allow user to type: $ perf record -e 'cpu/cpu-cycles,any' instead of: $ perf record -e 'cpu/cpu-cycles,any=1' However it works also for multi bits terms like: $ perf record -e 'cpu/event/' ls ... $ perf evlist -v ..., config: 0x1, ... After discussion with Peter we decided making such term usage to fail, like: $ perf record -e 'cpu/event/' ls event syntax error: 'cpu/event/' \___ no value assigned for term ... Signed-off-by: Jiri Olsa Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1487340058-10496-4-git-send-email-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/pmu.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'tools/perf/util/pmu.c') diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 49bfee0..63cb46c 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -834,9 +834,18 @@ static int pmu_config_term(struct list_head *formats, * Either directly use a numeric term, or try to translate string terms * using event parameters. */ - if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM) + if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM) { + if (term->no_value && + bitmap_weight(format->bits, PERF_PMU_FORMAT_BITS) > 1) { + if (err) { + err->idx = term->err_val; + err->str = strdup("no value assigned for term"); + } + return -EINVAL; + } + val = term->val.num; - else if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) { + } else if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) { if (strcmp(term->val.str, "?")) { if (verbose) { pr_info("Invalid sysfs entry %s=%s\n", -- cgit v1.1