Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Do not put a variable sized type not at the end of a struct

As this is a GNU extension and while harmless in this case, we can do
the same thing in a more clearer way by using an existing thread_map
constructor.

With this we avoid this while compiling with clang:

util/parse-events.c:2024:21: error: field 'map' with variable sized type 'struct thread_map' not at the end of a struct or class is a GNU extension
[-Werror,-Wgnu-variable-sized-type-not-at-end]
struct thread_map map;
^
1 error generated.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-tqocbplnyyhpst6drgm2u4m3@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+6 -9
+6 -9
tools/perf/util/parse-events.c
··· 2020 2020 .config = config, 2021 2021 .disabled = 1, 2022 2022 }; 2023 - struct { 2024 - struct thread_map map; 2025 - int threads[1]; 2026 - } tmap = { 2027 - .map.nr = 1, 2028 - .threads = { 0 }, 2029 - }; 2023 + struct thread_map *tmap = thread_map__new_by_tid(0); 2024 + 2025 + if (tmap == NULL) 2026 + return false; 2030 2027 2031 2028 evsel = perf_evsel__new(&attr); 2032 2029 if (evsel) { 2033 - open_return = perf_evsel__open(evsel, NULL, &tmap.map); 2030 + open_return = perf_evsel__open(evsel, NULL, tmap); 2034 2031 ret = open_return >= 0; 2035 2032 2036 2033 if (open_return == -EACCES) { ··· 2039 2042 * 2040 2043 */ 2041 2044 evsel->attr.exclude_kernel = 1; 2042 - ret = perf_evsel__open(evsel, NULL, &tmap.map) >= 0; 2045 + ret = perf_evsel__open(evsel, NULL, tmap) >= 0; 2043 2046 } 2044 2047 perf_evsel__delete(evsel); 2045 2048 }