--- /dev/null
+From d4913cbd05bab685e49c8174896e563b2487d054 Mon Sep 17 00:00:00 2001
+From: Markus Trippelsdorf <markus@trippelsdorf.de>
+Date: Mon, 14 Dec 2015 16:44:03 +0100
+Subject: perf annotate browser: Fix behaviour of Shift-Tab with nothing focussed
+
+From: Markus Trippelsdorf <markus@trippelsdorf.de>
+
+commit d4913cbd05bab685e49c8174896e563b2487d054 upstream.
+
+The issue was pointed out by gcc-6's -Wmisleading-indentation.
+
+Signed-off-by: Markus Trippelsdorf <markus@trippelsdorf.de>
+Acked-by: Ingo Molnar <mingo@kernel.org>
+Cc: Ben Hutchings <ben@decadent.org.uk>
+Cc: Matt Fleming <matt@codeblueprint.co.uk>
+Cc: Peter Zijlstra <peterz@infradead.org>
+Fixes: c97cf42219b7 ("perf top: Live TUI Annotation")
+Link: http://lkml.kernel.org/r/20151214154403.GB1409@x4
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/ui/browsers/annotate.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+--- a/tools/perf/ui/browsers/annotate.c
++++ b/tools/perf/ui/browsers/annotate.c
+@@ -755,11 +755,11 @@ static int annotate_browser__run(struct
+ nd = browser->curr_hot;
+ break;
+ case K_UNTAB:
+- if (nd != NULL)
++ if (nd != NULL) {
+ nd = rb_next(nd);
+ if (nd == NULL)
+ nd = rb_first(&browser->entries);
+- else
++ } else
+ nd = browser->curr_hot;
+ break;
+ case K_F1:
--- /dev/null
+From 3aff8ba0a4c9c9191bb788171a1c54778e1246a2 Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Thu, 9 Feb 2017 14:39:42 -0300
+Subject: perf bench numa: Avoid possible truncation when using snprintf()
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit 3aff8ba0a4c9c9191bb788171a1c54778e1246a2 upstream.
+
+Addressing this warning from gcc 7:
+
+ CC /tmp/build/perf/bench/numa.o
+ bench/numa.c: In function '__bench_numa':
+ bench/numa.c:1582:42: error: '%d' directive output may be truncated writing between 1 and 10 bytes into a region of size between 8 and 17 [-Werror=format-truncation=]
+ snprintf(tname, 32, "process%d:thread%d", p, t);
+ ^~
+ bench/numa.c:1582:25: note: directive argument in the range [0, 2147483647]
+ snprintf(tname, 32, "process%d:thread%d", p, t);
+ ^~~~~~~~~~~~~~~~~~~~
+ In file included from /usr/include/stdio.h:939:0,
+ from bench/../util/util.h:47,
+ from bench/../builtin.h:4,
+ from bench/numa.c:11:
+ /usr/include/bits/stdio2.h:64:10: note: '__builtin___snprintf_chk' output between 17 and 35 bytes into a destination of size 32
+ return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
+ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ __bos (__s), __fmt, __va_arg_pack ());
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ cc1: all warnings being treated as errors
+
+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: Petr Holasek <pholasek@redhat.com>
+Cc: Wang Nan <wangnan0@huawei.com>
+Link: http://lkml.kernel.org/n/tip-twa37vsfqcie5gwpqwnjuuz9@git.kernel.org
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/bench/numa.c | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+--- a/tools/perf/bench/numa.c
++++ b/tools/perf/bench/numa.c
+@@ -1570,13 +1570,13 @@ static int __bench_numa(const char *name
+ "GB/sec,", "total-speed", "GB/sec total speed");
+
+ if (g->p.show_details >= 2) {
+- char tname[32];
++ char tname[14 + 2 * 10 + 1];
+ struct thread_data *td;
+ for (p = 0; p < g->p.nr_proc; p++) {
+ for (t = 0; t < g->p.nr_threads; t++) {
+- memset(tname, 0, 32);
++ memset(tname, 0, sizeof(tname));
+ td = g->threads + p*g->p.nr_threads + t;
+- snprintf(tname, 32, "process%d:thread%d", p, t);
++ snprintf(tname, sizeof(tname), "process%d:thread%d", p, t);
+ print_res(tname, td->speed_gbs,
+ "GB/sec", "thread-speed", "GB/sec/thread speed");
+ print_res(tname, td->system_time_ns / 1e9,
--- /dev/null
+From 62aa0e177d278462145a29c30d3c8501ae57e200 Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Fri, 8 Apr 2016 12:04:29 -0300
+Subject: perf dwarf: Guard !x86_64 definitions under #ifdef else clause
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit 62aa0e177d278462145a29c30d3c8501ae57e200 upstream.
+
+To fix the build on Fedora Rawhide (gcc 6.0.0 20160311 (Red Hat 6.0.0-0.17):
+
+ CC /tmp/build/perf/arch/x86/util/dwarf-regs.o
+ arch/x86/util/dwarf-regs.c:66:36: error: 'x86_32_regoffset_table' defined but not used [-Werror=unused-const-variable=]
+ static const struct pt_regs_offset x86_32_regoffset_table[] = {
+ ^~~~~~~~~~~~~~~~~~~~~~
+ cc1: all warnings being treated as errors
+
+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-fghuksc1u8ln82bof4lwcj0o@git.kernel.org
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/arch/x86/util/dwarf-regs.c | 8 ++++----
+ 1 file changed, 4 insertions(+), 4 deletions(-)
+
+--- a/tools/perf/arch/x86/util/dwarf-regs.c
++++ b/tools/perf/arch/x86/util/dwarf-regs.c
+@@ -63,6 +63,8 @@ struct pt_regs_offset {
+ # define REG_OFFSET_NAME_32(n, r) {.name = n, .offset = offsetof(struct pt_regs, r)}
+ #endif
+
++/* TODO: switching by dwarf address size */
++#ifndef __x86_64__
+ static const struct pt_regs_offset x86_32_regoffset_table[] = {
+ REG_OFFSET_NAME_32("%ax", eax),
+ REG_OFFSET_NAME_32("%cx", ecx),
+@@ -75,6 +77,8 @@ static const struct pt_regs_offset x86_3
+ REG_OFFSET_END,
+ };
+
++#define regoffset_table x86_32_regoffset_table
++#else
+ static const struct pt_regs_offset x86_64_regoffset_table[] = {
+ REG_OFFSET_NAME_64("%ax", rax),
+ REG_OFFSET_NAME_64("%dx", rdx),
+@@ -95,11 +99,7 @@ static const struct pt_regs_offset x86_6
+ REG_OFFSET_END,
+ };
+
+-/* TODO: switching by dwarf address size */
+-#ifdef __x86_64__
+ #define regoffset_table x86_64_regoffset_table
+-#else
+-#define regoffset_table x86_32_regoffset_table
+ #endif
+
+ /* Minus 1 for the ending REG_OFFSET_END */
--- /dev/null
+From 7ea6856d6f5629d742edc23b8b76e6263371ef45 Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Thu, 9 Feb 2017 15:22:22 -0300
+Subject: perf intel-pt: Use __fallthrough
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit 7ea6856d6f5629d742edc23b8b76e6263371ef45 upstream.
+
+To address new warnings emmited by gcc 7, e.g.::
+
+ CC /tmp/build/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.o
+ CC /tmp/build/perf/tests/parse-events.o
+ util/intel-pt-decoder/intel-pt-pkt-decoder.c: In function 'intel_pt_pkt_desc':
+ util/intel-pt-decoder/intel-pt-pkt-decoder.c:499:6: error: this statement may fall through [-Werror=implicit-fallthrough=]
+ if (!(packet->count))
+ ^
+ util/intel-pt-decoder/intel-pt-pkt-decoder.c:501:2: note: here
+ case INTEL_PT_CYC:
+ ^~~~
+ CC /tmp/build/perf/util/intel-pt-decoder/intel-pt-decoder.o
+ cc1: all warnings being treated as errors
+
+Acked-by: Andi Kleen <ak@linux.intel.com>
+Cc: Adrian Hunter <adrian.hunter@intel.com>
+Cc: Alexander Shishkin <alexander.shishkin@linux.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-mf0hw789pu9x855us5l32c83@git.kernel.org
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 5 +++++
+ tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c | 2 ++
+ 2 files changed, 7 insertions(+)
+
+--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
++++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+@@ -22,6 +22,7 @@
+ #include <errno.h>
+ #include <stdint.h>
+ #include <inttypes.h>
++#include <linux/compiler.h>
+
+ #include "../cache.h"
+ #include "../util.h"
+@@ -1708,6 +1709,7 @@ static int intel_pt_walk_psb(struct inte
+ switch (decoder->packet.type) {
+ case INTEL_PT_TIP_PGD:
+ decoder->continuous_period = false;
++ __fallthrough;
+ case INTEL_PT_TIP_PGE:
+ case INTEL_PT_TIP:
+ intel_pt_log("ERROR: Unexpected packet\n");
+@@ -1762,6 +1764,8 @@ static int intel_pt_walk_psb(struct inte
+ decoder->pge = false;
+ decoder->continuous_period = false;
+ intel_pt_clear_tx_flags(decoder);
++ __fallthrough;
++
+ case INTEL_PT_TNT:
+ decoder->have_tma = false;
+ intel_pt_log("ERROR: Unexpected packet\n");
+@@ -1802,6 +1806,7 @@ static int intel_pt_walk_to_ip(struct in
+ switch (decoder->packet.type) {
+ case INTEL_PT_TIP_PGD:
+ decoder->continuous_period = false;
++ __fallthrough;
+ case INTEL_PT_TIP_PGE:
+ case INTEL_PT_TIP:
+ decoder->pge = decoder->packet.type != INTEL_PT_TIP_PGD;
+--- a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
++++ b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
+@@ -17,6 +17,7 @@
+ #include <string.h>
+ #include <endian.h>
+ #include <byteswap.h>
++#include <linux/compiler.h>
+
+ #include "intel-pt-pkt-decoder.h"
+
+@@ -488,6 +489,7 @@ int intel_pt_pkt_desc(const struct intel
+ case INTEL_PT_FUP:
+ if (!(packet->count))
+ return snprintf(buf, buf_len, "%s no ip", name);
++ __fallthrough;
+ case INTEL_PT_CYC:
+ case INTEL_PT_VMCS:
+ case INTEL_PT_MTC:
--- /dev/null
+From d85ce830eef6c10d1e9617172dea4681f02b8424 Mon Sep 17 00:00:00 2001
+From: Markus Trippelsdorf <markus@trippelsdorf.de>
+Date: Mon, 14 Dec 2015 16:44:40 +0100
+Subject: perf pmu: Fix misleadingly indented assignment (whitespace)
+
+From: Markus Trippelsdorf <markus@trippelsdorf.de>
+
+commit d85ce830eef6c10d1e9617172dea4681f02b8424 upstream.
+
+One line in perf_pmu__parse_unit() is indented wrongly, leading to a
+warning (=> error) from gcc 6:
+
+ util/pmu.c:156:3: error: statement is indented as if it were guarded by... [-Werror=misleading-indentation]
+
+ sret = read(fd, alias->unit, UNIT_MAX_LEN);
+ ^~~~
+
+ util/pmu.c:153:2: note: ...this 'if' clause, but it is not
+ if (fd == -1)
+ ^~
+
+Signed-off-by: Markus Trippelsdorf <markus@trippelsdorf.de>
+Acked-by: Ingo Molnar <mingo@kernel.org>
+Cc: Ben Hutchings <ben@decadent.org.uk>
+Cc: Matt Fleming <matt@codeblueprint.co.uk>
+Cc: Peter Zijlstra <peterz@infradead.org>
+Fixes: 410136f5dd96 ("tools/perf/stat: Add event unit and scale support")
+Link: http://lkml.kernel.org/r/20151214154440.GC1409@x4
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/util/pmu.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/tools/perf/util/pmu.c
++++ b/tools/perf/util/pmu.c
+@@ -153,7 +153,7 @@ static int perf_pmu__parse_unit(struct p
+ if (fd == -1)
+ return -1;
+
+- sret = read(fd, alias->unit, UNIT_MAX_LEN);
++ sret = read(fd, alias->unit, UNIT_MAX_LEN);
+ if (sret < 0)
+ goto error;
+
--- /dev/null
+From a5e8e825bd1704c488bf6a46936aaf3b9f203d6a Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Fri, 8 Apr 2016 11:25:59 -0300
+Subject: perf script: Use readdir() instead of deprecated readdir_r()
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit a5e8e825bd1704c488bf6a46936aaf3b9f203d6a upstream.
+
+The readdir() function is thread safe as long as just one thread uses a
+DIR, which is the case in 'perf script', so, to avoid breaking the build
+with glibc-2.23.90 (upcoming 2.24), use it instead of readdir_r().
+
+See: http://man7.org/linux/man-pages/man3/readdir.3.html
+
+"However, in modern implementations (including the glibc implementation),
+concurrent calls to readdir() that specify different directory streams
+are thread-safe. In cases where multiple threads must read from the
+same directory stream, using readdir() with external synchronization is
+still preferable to the use of the deprecated readdir_r(3) function."
+
+Noticed while building on a Fedora Rawhide docker container.
+
+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-mt3xz7n2hl49ni2vx7kuq74g@git.kernel.org
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/builtin-script.c | 70 +++++++++++++++++++++-----------------------
+ 1 file changed, 34 insertions(+), 36 deletions(-)
+
+--- a/tools/perf/builtin-script.c
++++ b/tools/perf/builtin-script.c
+@@ -1252,21 +1252,19 @@ static int is_directory(const char *base
+ return S_ISDIR(st.st_mode);
+ }
+
+-#define for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next)\
+- while (!readdir_r(scripts_dir, &lang_dirent, &lang_next) && \
+- lang_next) \
+- if ((lang_dirent.d_type == DT_DIR || \
+- (lang_dirent.d_type == DT_UNKNOWN && \
+- is_directory(scripts_path, &lang_dirent))) && \
+- (strcmp(lang_dirent.d_name, ".")) && \
+- (strcmp(lang_dirent.d_name, "..")))
+-
+-#define for_each_script(lang_path, lang_dir, script_dirent, script_next)\
+- while (!readdir_r(lang_dir, &script_dirent, &script_next) && \
+- script_next) \
+- if (script_dirent.d_type != DT_DIR && \
+- (script_dirent.d_type != DT_UNKNOWN || \
+- !is_directory(lang_path, &script_dirent)))
++#define for_each_lang(scripts_path, scripts_dir, lang_dirent) \
++ while ((lang_dirent = readdir(scripts_dir)) != NULL) \
++ if ((lang_dirent->d_type == DT_DIR || \
++ (lang_dirent->d_type == DT_UNKNOWN && \
++ is_directory(scripts_path, lang_dirent))) && \
++ (strcmp(lang_dirent->d_name, ".")) && \
++ (strcmp(lang_dirent->d_name, "..")))
++
++#define for_each_script(lang_path, lang_dir, script_dirent) \
++ while ((script_dirent = readdir(lang_dir)) != NULL) \
++ if (script_dirent->d_type != DT_DIR && \
++ (script_dirent->d_type != DT_UNKNOWN || \
++ !is_directory(lang_path, script_dirent)))
+
+
+ #define RECORD_SUFFIX "-record"
+@@ -1412,7 +1410,7 @@ static int list_available_scripts(const
+ const char *s __maybe_unused,
+ int unset __maybe_unused)
+ {
+- struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
++ struct dirent *script_dirent, *lang_dirent;
+ char scripts_path[MAXPATHLEN];
+ DIR *scripts_dir, *lang_dir;
+ char script_path[MAXPATHLEN];
+@@ -1427,19 +1425,19 @@ static int list_available_scripts(const
+ if (!scripts_dir)
+ return -1;
+
+- for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) {
++ for_each_lang(scripts_path, scripts_dir, lang_dirent) {
+ snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
+- lang_dirent.d_name);
++ lang_dirent->d_name);
+ lang_dir = opendir(lang_path);
+ if (!lang_dir)
+ continue;
+
+- for_each_script(lang_path, lang_dir, script_dirent, script_next) {
+- script_root = get_script_root(&script_dirent, REPORT_SUFFIX);
++ for_each_script(lang_path, lang_dir, script_dirent) {
++ script_root = get_script_root(script_dirent, REPORT_SUFFIX);
+ if (script_root) {
+ desc = script_desc__findnew(script_root);
+ snprintf(script_path, MAXPATHLEN, "%s/%s",
+- lang_path, script_dirent.d_name);
++ lang_path, script_dirent->d_name);
+ read_script_info(desc, script_path);
+ free(script_root);
+ }
+@@ -1527,7 +1525,7 @@ static int check_ev_match(char *dir_name
+ */
+ int find_scripts(char **scripts_array, char **scripts_path_array)
+ {
+- struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
++ struct dirent *script_dirent, *lang_dirent;
+ char scripts_path[MAXPATHLEN], lang_path[MAXPATHLEN];
+ DIR *scripts_dir, *lang_dir;
+ struct perf_session *session;
+@@ -1550,9 +1548,9 @@ int find_scripts(char **scripts_array, c
+ return -1;
+ }
+
+- for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) {
++ for_each_lang(scripts_path, scripts_dir, lang_dirent) {
+ snprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path,
+- lang_dirent.d_name);
++ lang_dirent->d_name);
+ #ifdef NO_LIBPERL
+ if (strstr(lang_path, "perl"))
+ continue;
+@@ -1566,16 +1564,16 @@ int find_scripts(char **scripts_array, c
+ if (!lang_dir)
+ continue;
+
+- for_each_script(lang_path, lang_dir, script_dirent, script_next) {
++ for_each_script(lang_path, lang_dir, script_dirent) {
+ /* Skip those real time scripts: xxxtop.p[yl] */
+- if (strstr(script_dirent.d_name, "top."))
++ if (strstr(script_dirent->d_name, "top."))
+ continue;
+ sprintf(scripts_path_array[i], "%s/%s", lang_path,
+- script_dirent.d_name);
+- temp = strchr(script_dirent.d_name, '.');
++ script_dirent->d_name);
++ temp = strchr(script_dirent->d_name, '.');
+ snprintf(scripts_array[i],
+- (temp - script_dirent.d_name) + 1,
+- "%s", script_dirent.d_name);
++ (temp - script_dirent->d_name) + 1,
++ "%s", script_dirent->d_name);
+
+ if (check_ev_match(lang_path,
+ scripts_array[i], session))
+@@ -1593,7 +1591,7 @@ int find_scripts(char **scripts_array, c
+
+ static char *get_script_path(const char *script_root, const char *suffix)
+ {
+- struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
++ struct dirent *script_dirent, *lang_dirent;
+ char scripts_path[MAXPATHLEN];
+ char script_path[MAXPATHLEN];
+ DIR *scripts_dir, *lang_dir;
+@@ -1606,21 +1604,21 @@ static char *get_script_path(const char
+ if (!scripts_dir)
+ return NULL;
+
+- for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) {
++ for_each_lang(scripts_path, scripts_dir, lang_dirent) {
+ snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
+- lang_dirent.d_name);
++ lang_dirent->d_name);
+ lang_dir = opendir(lang_path);
+ if (!lang_dir)
+ continue;
+
+- for_each_script(lang_path, lang_dir, script_dirent, script_next) {
+- __script_root = get_script_root(&script_dirent, suffix);
++ for_each_script(lang_path, lang_dir, script_dirent) {
++ __script_root = get_script_root(script_dirent, suffix);
+ if (__script_root && !strcmp(script_root, __script_root)) {
+ free(__script_root);
+ closedir(lang_dir);
+ closedir(scripts_dir);
+ snprintf(script_path, MAXPATHLEN, "%s/%s",
+- lang_path, script_dirent.d_name);
++ lang_path, script_dirent->d_name);
+ return strdup(script_path);
+ }
+ free(__script_root);
--- /dev/null
+From d7dd112ea5cacf91ae72c0714c3b911eb6016fea Mon Sep 17 00:00:00 2001
+From: Wang YanQing <udknight@gmail.com>
+Date: Sun, 12 Feb 2017 10:46:55 +0800
+Subject: perf scripting perl: Fix compile error with some perl5 versions
+
+From: Wang YanQing <udknight@gmail.com>
+
+commit d7dd112ea5cacf91ae72c0714c3b911eb6016fea upstream.
+
+Fix below compile error:
+
+ CC util/scripting-engines/trace-event-perl.o
+ In file included from /usr/lib/perl5/5.22.2/i686-linux/CORE/perl.h:5673:0,
+ from util/scripting-engines/trace-event-perl.c:31:
+ /usr/lib/perl5/5.22.2/i686-linux/CORE/inline.h: In function 'S__is_utf8_char_slow':
+ /usr/lib/perl5/5.22.2/i686-linux/CORE/inline.h:270:5: error: nested extern declaration of 'Perl___notused' [-Werror=nested-externs]
+ dTHX; /* The function called below requires thread context */
+ ^
+ cc1: all warnings being treated as errors
+
+After digging perl5 repository, I find out that we will meet this
+compile error with perl from v5.21.1 to v5.25.4
+
+Signed-off-by: Wang YanQing <udknight@gmail.com>
+Acked-by: Jiri Olsa <jolsa@kernel.org>
+Link: http://lkml.kernel.org/r/20170212024655.GA15997@udknight
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/util/scripting-engines/Build | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/tools/perf/util/scripting-engines/Build
++++ b/tools/perf/util/scripting-engines/Build
+@@ -1,6 +1,6 @@
+ libperf-$(CONFIG_LIBPERL) += trace-event-perl.o
+ libperf-$(CONFIG_LIBPYTHON) += trace-event-python.o
+
+-CFLAGS_trace-event-perl.o += $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow -Wno-undef -Wno-switch-default
++CFLAGS_trace-event-perl.o += $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow -Wno-nested-externs -Wno-undef -Wno-switch-default
+
+ CFLAGS_trace-event-python.o += $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow
--- /dev/null
+From 2e2bbc039fad9eabad6c4c1a473c8b2554cdd2d4 Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Thu, 9 Feb 2017 14:48:46 -0300
+Subject: perf tests: Avoid possible truncation with dirent->d_name + snprintf
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit 2e2bbc039fad9eabad6c4c1a473c8b2554cdd2d4 upstream.
+
+Addressing a few cases spotted by a new warning in gcc 7:
+
+ tests/parse-events.c: In function 'test_pmu_events':
+ tests/parse-events.c:1790:39: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 90 [-Werror=format-truncation=]
+ snprintf(name, MAX_NAME, "cpu/event=%s/u", ent->d_name);
+ ^~
+ In file included from /usr/include/stdio.h:939:0,
+ from /git/linux/tools/perf/util/map.h:9,
+ from /git/linux/tools/perf/util/symbol.h:7,
+ from /git/linux/tools/perf/util/evsel.h:10,
+ from tests/parse-events.c:3:
+ /usr/include/bits/stdio2.h:64:10: note: '__builtin___snprintf_chk' output between 13 and 268 bytes into a destination of size 100
+ return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
+ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ __bos (__s), __fmt, __va_arg_pack ());
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ tests/parse-events.c:1798:29: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 100 [-Werror=format-truncation=]
+ snprintf(name, MAX_NAME, "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name);
+
+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>
+Fixes: 945aea220bb8 ("perf tests: Move test objects into 'tests' directory")
+Link: http://lkml.kernel.org/n/tip-ty4q2p8zp1dp3mskvubxskm5@git.kernel.org
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/tests/parse-events.c | 8 +++-----
+ 1 file changed, 3 insertions(+), 5 deletions(-)
+
+--- a/tools/perf/tests/parse-events.c
++++ b/tools/perf/tests/parse-events.c
+@@ -1727,15 +1727,14 @@ static int test_pmu_events(void)
+ }
+
+ while (!ret && (ent = readdir(dir))) {
+-#define MAX_NAME 100
+ struct evlist_test e;
+- char name[MAX_NAME];
++ char name[2 * NAME_MAX + 1 + 12 + 3];
+
+ if (!strcmp(ent->d_name, ".") ||
+ !strcmp(ent->d_name, ".."))
+ continue;
+
+- snprintf(name, MAX_NAME, "cpu/event=%s/u", ent->d_name);
++ snprintf(name, sizeof(name), "cpu/event=%s/u", ent->d_name);
+
+ e.name = name;
+ e.check = test__checkevent_pmu_events;
+@@ -1743,11 +1742,10 @@ static int test_pmu_events(void)
+ ret = test_event(&e);
+ if (ret)
+ break;
+- snprintf(name, MAX_NAME, "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name);
++ snprintf(name, sizeof(name), "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name);
+ e.name = name;
+ e.check = test__checkevent_pmu_events_mix;
+ ret = test_event(&e);
+-#undef MAX_NAME
+ }
+
+ closedir(dir);
--- /dev/null
+From cf89813a5b514bff9b3b5e7eaf2090f22fba62e0 Mon Sep 17 00:00:00 2001
+From: Markus Trippelsdorf <markus@trippelsdorf.de>
+Date: Mon, 14 Dec 2015 16:43:35 +0100
+Subject: perf tests: Remove wrong semicolon in while loop in CQM test
+
+From: Markus Trippelsdorf <markus@trippelsdorf.de>
+
+commit cf89813a5b514bff9b3b5e7eaf2090f22fba62e0 upstream.
+
+The while loop was spinning. Fix by removing a semicolon.
+
+The issue was pointed out by gcc-6's -Wmisleading-indentation.
+
+Signed-off-by: Markus Trippelsdorf <markus@trippelsdorf.de>
+Reviewed-by: Matt Fleming <matt@codeblueprint.co.uk>
+Acked-by: Ingo Molnar <mingo@kernel.org>
+Cc: Ben Hutchings <ben@decadent.org.uk>
+Cc: Peter Zijlstra <peterz@infradead.org>
+Fixes: 035827e9f2bd ("perf tests: Add Intel CQM test")
+Link: http://lkml.kernel.org/r/20151214154335.GA1409@x4
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/arch/x86/tests/intel-cqm.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/tools/perf/arch/x86/tests/intel-cqm.c
++++ b/tools/perf/arch/x86/tests/intel-cqm.c
+@@ -17,7 +17,7 @@ static pid_t spawn(void)
+ if (pid)
+ return pid;
+
+- while(1);
++ while(1)
+ sleep(5);
+ return 0;
+ }
--- /dev/null
+From bdf23a9a190d7ecea092fd5c4aabb7d4bd0a9980 Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Wed, 8 Feb 2017 17:01:46 -0300
+Subject: perf thread_map: Correctly size buffer used with dirent->dt_name
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit bdf23a9a190d7ecea092fd5c4aabb7d4bd0a9980 upstream.
+
+The size of dirent->dt_name is NAME_MAX + 1, but the size for the 'path'
+buffer is hard coded at 256, which may truncate it because we also
+prepend "/proc/", so that all that into account and thank gcc 7 for this
+warning:
+
+ /git/linux/tools/perf/util/thread_map.c: In function 'thread_map__new_by_uid':
+ /git/linux/tools/perf/util/thread_map.c:119:39: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 250 [-Werror=format-truncation=]
+ snprintf(path, sizeof(path), "/proc/%s", dirent->d_name);
+ ^~
+ In file included from /usr/include/stdio.h:939:0,
+ from /git/linux/tools/perf/util/thread_map.c:5:
+ /usr/include/bits/stdio2.h:64:10: note: '__builtin___snprintf_chk' output between 7 and 262 bytes into a destination of size 256
+ return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
+ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ __bos (__s), __fmt, __va_arg_pack ());
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+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-csy0r8zrvz5efccgd4k12c82@git.kernel.org
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/util/thread_map.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/tools/perf/util/thread_map.c
++++ b/tools/perf/util/thread_map.c
+@@ -92,7 +92,7 @@ struct thread_map *thread_map__new_by_ui
+ {
+ DIR *proc;
+ int max_threads = 32, items, i;
+- char path[256];
++ char path[NAME_MAX + 1 + 6];
+ struct dirent dirent, *next, **namelist = NULL;
+ struct thread_map *threads = thread_map__alloc(max_threads);
+
--- /dev/null
+From 3354cf71104de49326d19d2f9bdb1f66eea52ef4 Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Fri, 8 Apr 2016 11:31:24 -0300
+Subject: perf thread_map: Use readdir() instead of deprecated readdir_r()
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit 3354cf71104de49326d19d2f9bdb1f66eea52ef4 upstream.
+
+The readdir() function is thread safe as long as just one thread uses a
+DIR, which is the case in thread_map, so, to avoid breaking the build
+with glibc-2.23.90 (upcoming 2.24), use it instead of readdir_r().
+
+See: http://man7.org/linux/man-pages/man3/readdir.3.html
+
+"However, in modern implementations (including the glibc implementation),
+concurrent calls to readdir() that specify different directory streams
+are thread-safe. In cases where multiple threads must read from the
+same directory stream, using readdir() with external synchronization is
+still preferable to the use of the deprecated readdir_r(3) function."
+
+Noticed while building on a Fedora Rawhide docker container.
+
+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-del8h2a0f40z75j4r42l96l0@git.kernel.org
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/util/thread_map.c | 8 ++++----
+ 1 file changed, 4 insertions(+), 4 deletions(-)
+
+--- a/tools/perf/util/thread_map.c
++++ b/tools/perf/util/thread_map.c
+@@ -93,7 +93,7 @@ struct thread_map *thread_map__new_by_ui
+ DIR *proc;
+ int max_threads = 32, items, i;
+ char path[NAME_MAX + 1 + 6];
+- struct dirent dirent, *next, **namelist = NULL;
++ struct dirent *dirent, **namelist = NULL;
+ struct thread_map *threads = thread_map__alloc(max_threads);
+
+ if (threads == NULL)
+@@ -106,16 +106,16 @@ struct thread_map *thread_map__new_by_ui
+ threads->nr = 0;
+ atomic_set(&threads->refcnt, 1);
+
+- while (!readdir_r(proc, &dirent, &next) && next) {
++ while ((dirent = readdir(proc)) != NULL) {
+ char *end;
+ bool grow = false;
+ struct stat st;
+- pid_t pid = strtol(dirent.d_name, &end, 10);
++ pid_t pid = strtol(dirent->d_name, &end, 10);
+
+ if (*end) /* only interested in proper numerical dirents */
+ continue;
+
+- snprintf(path, sizeof(path), "/proc/%s", dirent.d_name);
++ snprintf(path, sizeof(path), "/proc/%s", dirent->d_name);
+
+ if (stat(path, &st) != 0)
+ continue;
--- /dev/null
+From 3b556bced46aa6b1873da7faa18eff235e896adc Mon Sep 17 00:00:00 2001
+From: Eric Engestrom <eric.engestrom@imgtec.com>
+Date: Mon, 25 Apr 2016 10:47:54 +0100
+Subject: perf tools: Remove duplicate const qualifier
+
+From: Eric Engestrom <eric.engestrom@imgtec.com>
+
+commit 3b556bced46aa6b1873da7faa18eff235e896adc upstream.
+
+Signed-off-by: Eric Engestrom <eric.engestrom@imgtec.com>
+Cc: Adrian Hunter <adrian.hunter@intel.com>
+Cc: David Ahern <dsahern@gmail.com>
+Cc: Peter Zijlstra <peterz@infradead.org>
+Link: http://lkml.kernel.org/r/1461577678-29517-1-git-send-email-eric.engestrom@imgtec.com
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/util/thread.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/tools/perf/util/thread.c
++++ b/tools/perf/util/thread.c
+@@ -227,7 +227,7 @@ void thread__find_cpumode_addr_location(
+ struct addr_location *al)
+ {
+ size_t i;
+- const u8 const cpumodes[] = {
++ const u8 cpumodes[] = {
+ PERF_RECORD_MISC_USER,
+ PERF_RECORD_MISC_KERNEL,
+ PERF_RECORD_MISC_GUEST_USER,
--- /dev/null
+From 22a9f41b555673e7499b97acf3ffb07bf0af31ad Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Fri, 8 Apr 2016 11:53:02 -0300
+Subject: perf tools: Use readdir() instead of deprecated readdir_r() again
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit 22a9f41b555673e7499b97acf3ffb07bf0af31ad upstream.
+
+The readdir() function is thread safe as long as just one thread uses a
+DIR, which is the case when parsing tracepoint event definitions, to
+avoid breaking the build with glibc-2.23.90 (upcoming 2.24), use it
+instead of readdir_r().
+
+See: http://man7.org/linux/man-pages/man3/readdir.3.html
+
+"However, in modern implementations (including the glibc implementation),
+concurrent calls to readdir() that specify different directory streams
+are thread-safe. In cases where multiple threads must read from the
+same directory stream, using readdir() with external synchronization is
+still preferable to the use of the deprecated readdir_r(3) function."
+
+Noticed while building on a Fedora Rawhide docker container.
+
+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-wddn49r6bz6wq4ee3dxbl7lo@git.kernel.org
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/util/parse-events.c | 60 ++++++++++++++++++++---------------------
+ 1 file changed, 30 insertions(+), 30 deletions(-)
+
+--- a/tools/perf/util/parse-events.c
++++ b/tools/perf/util/parse-events.c
+@@ -138,11 +138,11 @@ struct event_symbol event_symbols_sw[PER
+ #define PERF_EVENT_TYPE(config) __PERF_EVENT_FIELD(config, TYPE)
+ #define PERF_EVENT_ID(config) __PERF_EVENT_FIELD(config, EVENT)
+
+-#define for_each_subsystem(sys_dir, sys_dirent, sys_next) \
+- while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next) \
+- if (sys_dirent.d_type == DT_DIR && \
+- (strcmp(sys_dirent.d_name, ".")) && \
+- (strcmp(sys_dirent.d_name, "..")))
++#define for_each_subsystem(sys_dir, sys_dirent) \
++ while ((sys_dirent = readdir(sys_dir)) != NULL) \
++ if (sys_dirent->d_type == DT_DIR && \
++ (strcmp(sys_dirent->d_name, ".")) && \
++ (strcmp(sys_dirent->d_name, "..")))
+
+ static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir)
+ {
+@@ -159,12 +159,12 @@ static int tp_event_has_id(struct dirent
+ return 0;
+ }
+
+-#define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) \
+- while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next) \
+- if (evt_dirent.d_type == DT_DIR && \
+- (strcmp(evt_dirent.d_name, ".")) && \
+- (strcmp(evt_dirent.d_name, "..")) && \
+- (!tp_event_has_id(&sys_dirent, &evt_dirent)))
++#define for_each_event(sys_dirent, evt_dir, evt_dirent) \
++ while ((evt_dirent = readdir(evt_dir)) != NULL) \
++ if (evt_dirent->d_type == DT_DIR && \
++ (strcmp(evt_dirent->d_name, ".")) && \
++ (strcmp(evt_dirent->d_name, "..")) && \
++ (!tp_event_has_id(sys_dirent, evt_dirent)))
+
+ #define MAX_EVENT_LENGTH 512
+
+@@ -173,7 +173,7 @@ struct tracepoint_path *tracepoint_id_to
+ {
+ struct tracepoint_path *path = NULL;
+ DIR *sys_dir, *evt_dir;
+- struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
++ struct dirent *sys_dirent, *evt_dirent;
+ char id_buf[24];
+ int fd;
+ u64 id;
+@@ -184,18 +184,18 @@ struct tracepoint_path *tracepoint_id_to
+ if (!sys_dir)
+ return NULL;
+
+- for_each_subsystem(sys_dir, sys_dirent, sys_next) {
++ for_each_subsystem(sys_dir, sys_dirent) {
+
+ snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path,
+- sys_dirent.d_name);
++ sys_dirent->d_name);
+ evt_dir = opendir(dir_path);
+ if (!evt_dir)
+ continue;
+
+- for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
++ for_each_event(sys_dirent, evt_dir, evt_dirent) {
+
+ snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path,
+- evt_dirent.d_name);
++ evt_dirent->d_name);
+ fd = open(evt_path, O_RDONLY);
+ if (fd < 0)
+ continue;
+@@ -220,9 +220,9 @@ struct tracepoint_path *tracepoint_id_to
+ free(path);
+ return NULL;
+ }
+- strncpy(path->system, sys_dirent.d_name,
++ strncpy(path->system, sys_dirent->d_name,
+ MAX_EVENT_LENGTH);
+- strncpy(path->name, evt_dirent.d_name,
++ strncpy(path->name, evt_dirent->d_name,
+ MAX_EVENT_LENGTH);
+ return path;
+ }
+@@ -1629,7 +1629,7 @@ void print_tracepoint_events(const char
+ bool name_only)
+ {
+ DIR *sys_dir, *evt_dir;
+- struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
++ struct dirent *sys_dirent, *evt_dirent;
+ char evt_path[MAXPATHLEN];
+ char dir_path[MAXPATHLEN];
+ char **evt_list = NULL;
+@@ -1647,20 +1647,20 @@ restart:
+ goto out_close_sys_dir;
+ }
+
+- for_each_subsystem(sys_dir, sys_dirent, sys_next) {
++ for_each_subsystem(sys_dir, sys_dirent) {
+ if (subsys_glob != NULL &&
+- !strglobmatch(sys_dirent.d_name, subsys_glob))
++ !strglobmatch(sys_dirent->d_name, subsys_glob))
+ continue;
+
+ snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path,
+- sys_dirent.d_name);
++ sys_dirent->d_name);
+ evt_dir = opendir(dir_path);
+ if (!evt_dir)
+ continue;
+
+- for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
++ for_each_event(sys_dirent, evt_dir, evt_dirent) {
+ if (event_glob != NULL &&
+- !strglobmatch(evt_dirent.d_name, event_glob))
++ !strglobmatch(evt_dirent->d_name, event_glob))
+ continue;
+
+ if (!evt_num_known) {
+@@ -1669,7 +1669,7 @@ restart:
+ }
+
+ snprintf(evt_path, MAXPATHLEN, "%s:%s",
+- sys_dirent.d_name, evt_dirent.d_name);
++ sys_dirent->d_name, evt_dirent->d_name);
+
+ evt_list[evt_i] = strdup(evt_path);
+ if (evt_list[evt_i] == NULL)
+@@ -1722,7 +1722,7 @@ out_close_sys_dir:
+ int is_valid_tracepoint(const char *event_string)
+ {
+ DIR *sys_dir, *evt_dir;
+- struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
++ struct dirent *sys_dirent, *evt_dirent;
+ char evt_path[MAXPATHLEN];
+ char dir_path[MAXPATHLEN];
+
+@@ -1730,17 +1730,17 @@ int is_valid_tracepoint(const char *even
+ if (!sys_dir)
+ return 0;
+
+- for_each_subsystem(sys_dir, sys_dirent, sys_next) {
++ for_each_subsystem(sys_dir, sys_dirent) {
+
+ snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path,
+- sys_dirent.d_name);
++ sys_dirent->d_name);
+ evt_dir = opendir(dir_path);
+ if (!evt_dir)
+ continue;
+
+- for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
++ for_each_event(sys_dirent, evt_dir, evt_dirent) {
+ snprintf(evt_path, MAXPATHLEN, "%s:%s",
+- sys_dirent.d_name, evt_dirent.d_name);
++ sys_dirent->d_name, evt_dirent->d_name);
+ if (!strcmp(evt_path, event_string)) {
+ closedir(evt_dir);
+ closedir(sys_dir);
--- /dev/null
+From 7093b4c963cc4e344e490c774924a180602a7092 Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Fri, 8 Apr 2016 11:32:15 -0300
+Subject: perf tools: Use readdir() instead of deprecated readdir_r()
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit 7093b4c963cc4e344e490c774924a180602a7092 upstream.
+
+The readdir() function is thread safe as long as just one thread uses a
+DIR, which is the case when synthesizing events for pre-existing threads
+by traversing /proc, so, to avoid breaking the build with glibc-2.23.90
+(upcoming 2.24), use it instead of readdir_r().
+
+See: http://man7.org/linux/man-pages/man3/readdir.3.html
+
+"However, in modern implementations (including the glibc implementation),
+concurrent calls to readdir() that specify different directory streams
+are thread-safe. In cases where multiple threads must read from the
+same directory stream, using readdir() with external synchronization is
+still preferable to the use of the deprecated readdir_r(3) function."
+
+Noticed while building on a Fedora Rawhide docker container.
+
+ CC /tmp/build/perf/util/event.o
+ util/event.c: In function '__event__synthesize_thread':
+ util/event.c:466:2: error: 'readdir_r' is deprecated [-Werror=deprecated-declarations]
+ while (!readdir_r(tasks, &dirent, &next) && next) {
+ ^~~~~
+ In file included from /usr/include/features.h:368:0,
+ from /usr/include/stdint.h:25,
+ from /usr/lib/gcc/x86_64-redhat-linux/6.0.0/include/stdint.h:9,
+ from /git/linux/tools/include/linux/types.h:6,
+ from util/event.c:1:
+ /usr/include/dirent.h:189:12: note: declared here
+
+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-i1vj7nyjp2p750rirxgrfd3c@git.kernel.org
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/util/event.c | 12 ++++++------
+ 1 file changed, 6 insertions(+), 6 deletions(-)
+
+--- a/tools/perf/util/event.c
++++ b/tools/perf/util/event.c
+@@ -416,7 +416,7 @@ static int __event__synthesize_thread(un
+ {
+ char filename[PATH_MAX];
+ DIR *tasks;
+- struct dirent dirent, *next;
++ struct dirent *dirent;
+ pid_t tgid, ppid;
+ int rc = 0;
+
+@@ -445,11 +445,11 @@ static int __event__synthesize_thread(un
+ return 0;
+ }
+
+- while (!readdir_r(tasks, &dirent, &next) && next) {
++ while ((dirent = readdir(tasks)) != NULL) {
+ char *end;
+ pid_t _pid;
+
+- _pid = strtol(dirent.d_name, &end, 10);
++ _pid = strtol(dirent->d_name, &end, 10);
+ if (*end)
+ continue;
+
+@@ -558,7 +558,7 @@ int perf_event__synthesize_threads(struc
+ {
+ DIR *proc;
+ char proc_path[PATH_MAX];
+- struct dirent dirent, *next;
++ struct dirent *dirent;
+ union perf_event *comm_event, *mmap_event, *fork_event;
+ int err = -1;
+
+@@ -583,9 +583,9 @@ int perf_event__synthesize_threads(struc
+ if (proc == NULL)
+ goto out_free_fork;
+
+- while (!readdir_r(proc, &dirent, &next) && next) {
++ while ((dirent = readdir(proc)) != NULL) {
+ char *end;
+- pid_t pid = strtol(dirent.d_name, &end, 10);
++ pid_t pid = strtol(dirent->d_name, &end, 10);
+
+ if (*end) /* only interested in proper numerical dirents */
+ continue;
--- /dev/null
+From 7b0214b702ad8e124e039a317beeebb3f020d125 Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Wed, 8 Feb 2017 17:01:46 -0300
+Subject: perf top: Use __fallthrough
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit 7b0214b702ad8e124e039a317beeebb3f020d125 upstream.
+
+The implicit fall through case label here is intended, so let us inform
+that to gcc >= 7:
+
+ CC /tmp/build/perf/builtin-top.o
+ builtin-top.c: In function 'display_thread':
+ builtin-top.c:644:7: error: this statement may fall through [-Werror=implicit-fallthrough=]
+ if (errno == EINTR)
+ ^
+ builtin-top.c:647:3: note: here
+ default:
+ ^~~~~~~
+
+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-lmcfnnyx9ic0m6j0aud98p4e@git.kernel.org
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/builtin-top.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/tools/perf/builtin-top.c
++++ b/tools/perf/builtin-top.c
+@@ -636,7 +636,7 @@ repeat:
+ case -1:
+ if (errno == EINTR)
+ continue;
+- /* Fall trhu */
++ __fallthrough;
+ default:
+ c = getc(stdin);
+ tcsetattr(0, TCSAFLUSH, &save);
--- /dev/null
+From 3ed5ca2efff70e9f589087c2013789572901112d Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Wed, 30 Mar 2016 16:51:17 -0300
+Subject: perf trace: Do not process PERF_RECORD_LOST twice
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit 3ed5ca2efff70e9f589087c2013789572901112d upstream.
+
+We catch this record to provide a visual indication that events are
+getting lost, then call the default method to allow extra logging shared
+with the other tools to take place.
+
+This extra logging was done twice because we were continuing to the
+"default" clause where machine__process_event() will end up calling
+machine__process_lost_event() again, fix it.
+
+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-wus2zlhw3qo24ye84ewu4aqw@git.kernel.org
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/builtin-trace.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+--- a/tools/perf/builtin-trace.c
++++ b/tools/perf/builtin-trace.c
+@@ -1617,6 +1617,7 @@ static int trace__process_event(struct t
+ color_fprintf(trace->output, PERF_COLOR_RED,
+ "LOST %" PRIu64 " events!\n", event->lost.lost);
+ ret = machine__process_lost_event(machine, event, sample);
++ break;
+ default:
+ ret = machine__process_event(machine, event, sample);
+ break;
keys-fix-an-error-code-in-request_master_key.patch
rdma-uverbs-check-port-number-supplied-by-user-verbs-cmds.patch
mqueue-fix-a-use-after-free-in-sys_mq_notify.patch
+tools-include-add-a-__fallthrough-statement.patch
+tools-string-use-__fallthrough-in-perf_atoll.patch
+tools-strfilter-use-__fallthrough.patch
+perf-top-use-__fallthrough.patch
+perf-intel-pt-use-__fallthrough.patch
+perf-thread_map-correctly-size-buffer-used-with-dirent-dt_name.patch
+perf-scripting-perl-fix-compile-error-with-some-perl5-versions.patch
+perf-tests-avoid-possible-truncation-with-dirent-d_name-snprintf.patch
+perf-bench-numa-avoid-possible-truncation-when-using-snprintf.patch
+perf-tools-use-readdir-instead-of-deprecated-readdir_r.patch
+perf-thread_map-use-readdir-instead-of-deprecated-readdir_r.patch
+perf-script-use-readdir-instead-of-deprecated-readdir_r.patch
+perf-tools-remove-duplicate-const-qualifier.patch
+perf-annotate-browser-fix-behaviour-of-shift-tab-with-nothing-focussed.patch
+perf-pmu-fix-misleadingly-indented-assignment-whitespace.patch
+perf-dwarf-guard-x86_64-definitions-under-ifdef-else-clause.patch
+perf-trace-do-not-process-perf_record_lost-twice.patch
+perf-tests-remove-wrong-semicolon-in-while-loop-in-cqm-test.patch
+perf-tools-use-readdir-instead-of-deprecated-readdir_r-again.patch
--- /dev/null
+From b5bf1733d6a391c4e90ea8f8468d83023be74a2a Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Wed, 8 Feb 2017 17:01:46 -0300
+Subject: tools include: Add a __fallthrough statement
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit b5bf1733d6a391c4e90ea8f8468d83023be74a2a upstream.
+
+For cases where implicit fall through case labels are intended,
+to let us inform that to gcc >= 7:
+
+ CC /tmp/build/perf/util/string.o
+ util/string.c: In function 'perf_atoll':
+ util/string.c:22:7: error: this statement may fall through [-Werror=implicit-fallthrough=]
+ if (*p)
+ ^
+ util/string.c:24:3: note: here
+ case '\0':
+ ^~~~
+
+So we introduce:
+
+ #define __fallthrough __attribute__ ((fallthrough))
+
+And use it in such cases.
+
+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>
+Cc: William Cohen <wcohen@redhat.com>
+Link: http://lkml.kernel.org/n/tip-qnpig0xfop4hwv6k4mv1wts5@git.kernel.org
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/include/linux/compiler.h | 9 +++++++++
+ 1 file changed, 9 insertions(+)
+
+--- a/tools/include/linux/compiler.h
++++ b/tools/include/linux/compiler.h
+@@ -115,4 +115,13 @@ static __always_inline void __write_once
+ #define WRITE_ONCE(x, val) \
+ ({ union { typeof(x) __val; char __c[1]; } __u = { .__val = (val) }; __write_once_size(&(x), __u.__c, sizeof(x)); __u.__val; })
+
++
++#ifndef __fallthrough
++# if defined(__GNUC__) && __GNUC__ >= 7
++# define __fallthrough __attribute__ ((fallthrough))
++# else
++# define __fallthrough
++# endif
++#endif
++
+ #endif /* _TOOLS_LINUX_COMPILER_H */
--- /dev/null
+From d64b721d27aef3fbeb16ecda9dd22ee34818ff70 Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Wed, 8 Feb 2017 17:01:46 -0300
+Subject: tools strfilter: Use __fallthrough
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit d64b721d27aef3fbeb16ecda9dd22ee34818ff70 upstream.
+
+The implicit fall through case label here is intended, so let us inform
+that to gcc >= 7:
+
+ util/strfilter.c: In function 'strfilter_node__sprint':
+ util/strfilter.c:270:6: error: this statement may fall through [-Werror=implicit-fallthrough=]
+ if (len < 0)
+ ^
+ util/strfilter.c:272:2: note: here
+ case '!':
+ ^~~~
+ cc1: all warnings being treated as errors
+
+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-z2dpywg7u8fim000hjfbpyfm@git.kernel.org
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/util/strfilter.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+--- a/tools/perf/util/strfilter.c
++++ b/tools/perf/util/strfilter.c
+@@ -269,6 +269,7 @@ static int strfilter_node__sprint(struct
+ len = strfilter_node__sprint_pt(node->l, buf);
+ if (len < 0)
+ return len;
++ __fallthrough;
+ case '!':
+ if (buf) {
+ *(buf + len++) = *node->p;
--- /dev/null
+From 94bdd5edb34e472980d1e18b4600d6fb92bd6b0a Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Wed, 8 Feb 2017 17:01:46 -0300
+Subject: tools string: Use __fallthrough in perf_atoll()
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit 94bdd5edb34e472980d1e18b4600d6fb92bd6b0a upstream.
+
+The implicit fall through case label here is intended, so let us inform
+that to gcc >= 7:
+
+ CC /tmp/build/perf/util/string.o
+ util/string.c: In function 'perf_atoll':
+ util/string.c:22:7: error: this statement may fall through [-Werror=implicit-fallthrough=]
+ if (*p)
+ ^
+ util/string.c:24:3: note: here
+ case '\0':
+ ^~~~
+
+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-0ophb30v9apkk6o95el0rqlq@git.kernel.org
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/util/string.c | 2 ++
+ 1 file changed, 2 insertions(+)
+
+--- a/tools/perf/util/string.c
++++ b/tools/perf/util/string.c
+@@ -21,6 +21,8 @@ s64 perf_atoll(const char *str)
+ case 'b': case 'B':
+ if (*p)
+ goto out_err;
++
++ __fallthrough;
+ case '\0':
+ return length;
+ default: