perf parse-events: Avoid use uninitialized warning
authorIan Rogers <irogers@google.com>
Mon, 24 Jul 2023 20:12:45 +0000 (13:12 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 24 Jul 2023 21:23:52 +0000 (18:23 -0300)
With GCC LTO a potential use uninitialized is spotted:
```
In function ‘parse_events_config_bpf’,
    inlined from ‘parse_events_load_bpf’ at util/parse-events.c:874:8:
util/parse-events.c:792:37: error: ‘error_pos’ may be used uninitialized [-Werror=maybe-uninitialized]
  792 |                                 idx = term->err_term + error_pos;
      |                                     ^
util/parse-events.c: In function ‘parse_events_load_bpf’:
util/parse-events.c:765:13: note: ‘error_pos’ was declared here
  765 |         int error_pos;
      |             ^
```
So initialize at declaration.

Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Carsten Haitzler <carsten.haitzler@arm.com>
Cc: Fangrui Song <maskray@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Tom Rix <trix@redhat.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Cc: Yang Jihong <yangjihong1@huawei.com>
Cc: bpf@vger.kernel.org
Cc: llvm@lists.linux.dev
Link: https://lore.kernel.org/r/20230724201247.748146-3-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/parse-events.c

index acde097..da29061 100644 (file)
@@ -762,7 +762,7 @@ parse_events_config_bpf(struct parse_events_state *parse_state,
                        struct list_head *head_config)
 {
        struct parse_events_term *term;
-       int error_pos;
+       int error_pos = 0;
 
        if (!head_config || list_empty(head_config))
                return 0;