perf/core improvements and fixes
Subsystems (5)
Arnaldo Carvalho de Melo
maintainerHi Ingo,
Please consider pulling,
Best regards,
- Arnaldo
Test results at the end of this message, as usual.
The following changes since commit d1d59b817939821bee149e870ce7723f61ffb512:
Merge tag 'perf-urgent-for-mingo-5.3-20190708-2' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core (2019-07-09 13:22:03 +0200)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-core-for-mingo-5.3-20190709
for you to fetch changes up to 323fd749821daab0f327ec86d707c4542963cdb0:
perf intel-pt: Fix potential NULL pointer dereference found by the smatch tool (2019-07-09 10:13:28 -0300)
----------------------------------------------------------------
perf/core improvements and fixes:
Intel PT:
Adrian Hunter:
- Fix DROP VIEW power_events_view in the postgresql and sqlite export-db python scripts.
perf script:
Song Liu:
- Assume native_arch for pipe mode, fixing a segfault.
perf inject:
Arnaldo Carvalho de Melo:
- The tool->read() call may pass a NULL evsel, handle it.
core:
Arnaldo Carvalho de Melo:
- Move zalloc/zfree.c to tools/lib, further eroding tools/perf/util.[ch]
- Use zfree() where applicable instead of open coded equivalent.
- Add stdlib.h and some other headers to places where its needed and were getting via util.h, that doesn't need that anymore.
- Use list_del_init() more thoroughly.
Miscellaneous:
Leo Yan:
- Fix use after free and potential NULL pointer derefs detected by the smatch tool in various places.
Luke Mujica:
- Remove a couple unused variables in the parse-events code.
Numfor Mbiziwo-Tiapo:
- Initialize variable to suppress memory sanitizer warning in the mmap-thread-lookup 'perf test' entry.
----------------------------------------------------------------
Adrian Hunter (2):
perf scripts python: export-to-postgresql.py: Fix DROP VIEW power_events_view perf scripts python: export-to-sqlite.py: Fix DROP VIEW power_events_view
Arnaldo Carvalho de Melo (9):
perf inject: The tool->read() call may pass a NULL evsel, handle it perf evsel: perf_evsel__name(NULL) is valid, no need to check evsel perf tools: Add missing headers, mostly stdlib.h
perf namespaces: Move the conditional setns() prototype to namespaces.h perf tools: Move get_current_dir_name() cond prototype out of util.h tools lib: Adopt zalloc()/zfree() from tools/perf
perf tools: Use zfree() where applicable
perf tools: Use list_del_init() more thorougly
perf metricgroup: Add missing list_del_init() when flushing egroups list
Leo Yan (10):
perf stat: Fix use-after-freed pointer detected by the smatch tool perf top: Fix potential NULL pointer dereference detected by the smatch tool perf annotate: Fix dereferencing freed memory found by the smatch tool perf trace: Fix potential NULL pointer dereference found by the smatch tool perf map: Fix potential NULL pointer dereference found by smatch tool perf session: Fix potential NULL pointer dereference found by the smatch tool perf cs-etm: Fix potential NULL pointer dereference found by the smatch tool perf hists browser: Fix potential NULL pointer dereference found by the smatch tool perf intel-bts: Fix potential NULL pointer dereference found by the smatch tool perf intel-pt: Fix potential NULL pointer dereference found by the smatch tool
Luke Mujica (2):
perf parse-events: Remove unused variable 'i' perf parse-events: Remove unused variable: error
Numfor Mbiziwo-Tiapo (1):
perf test mmap-thread-lookup: Initialize variable to suppress memory sanitizer warning
Song Liu (1):
perf script: Assume native_arch for pipe mode
tools/include/linux/zalloc.h | 12 +++++ tools/lib/zalloc.c | 15 ++++++ tools/perf/MANIFEST | 1 + tools/perf/arch/arm/annotate/instructions.c | 1 + tools/perf/arch/arm/util/auxtrace.c | 1 + tools/perf/arch/arm/util/cs-etm.c | 1 + tools/perf/arch/arm64/util/arm-spe.c | 1 + tools/perf/arch/common.c | 3 +- tools/perf/arch/powerpc/util/perf_regs.c | 4 +- tools/perf/arch/s390/util/auxtrace.c | 1 + tools/perf/arch/s390/util/header.c | 3 +- tools/perf/arch/x86/util/event.c | 2 +- tools/perf/arch/x86/util/intel-bts.c | 2 +- tools/perf/arch/x86/util/intel-pt.c | 2 +- tools/perf/arch/x86/util/perf_regs.c | 2 +- tools/perf/bench/futex-hash.c | 3 +- tools/perf/bench/futex-lock-pi.c | 3 +- tools/perf/bench/mem-functions.c | 2 +- tools/perf/bench/numa.c | 2 +- tools/perf/builtin-annotate.c | 2 +- tools/perf/builtin-bench.c | 2 +- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-config.c | 1 + tools/perf/builtin-diff.c | 2 +- tools/perf/builtin-ftrace.c | 2 +- tools/perf/builtin-help.c | 2 + tools/perf/builtin-inject.c | 2 +- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-kvm.c | 2 +- tools/perf/builtin-lock.c | 10 ++-- tools/perf/builtin-probe.c | 2 +- tools/perf/builtin-record.c | 4 +- tools/perf/builtin-report.c | 4 +- tools/perf/builtin-sched.c | 2 +- tools/perf/builtin-script.c | 5 +- tools/perf/builtin-stat.c | 8 ++-- tools/perf/builtin-timechart.c | 4 +- tools/perf/builtin-top.c | 8 +++- tools/perf/builtin-trace.c | 7 +-- tools/perf/perf.c | 2 +- tools/perf/pmu-events/jevents.c | 2 +- tools/perf/scripts/python/export-to-postgresql.py | 2 +- tools/perf/scripts/python/export-to-sqlite.py | 2 +- tools/perf/tests/dwarf-unwind.c | 5 +- tools/perf/tests/expr.c | 3 +- tools/perf/tests/llvm.c | 1 + tools/perf/tests/mem2node.c | 3 +- tools/perf/tests/mmap-thread-lookup.c | 2 +- tools/perf/tests/sample-parsing.c | 1 + tools/perf/tests/switch-tracking.c | 3 +- tools/perf/tests/thread-map.c | 3 +- tools/perf/tests/vmlinux-kallsyms.c | 1 + tools/perf/ui/browser.c | 2 +- tools/perf/ui/browser.h | 1 + tools/perf/ui/browsers/annotate.c | 2 +- tools/perf/ui/browsers/hists.c | 17 +++++-- tools/perf/ui/browsers/map.c | 1 + tools/perf/ui/browsers/res_sample.c | 6 +-- tools/perf/ui/browsers/scripts.c | 4 +- tools/perf/ui/gtk/annotate.c | 2 +- tools/perf/ui/gtk/util.c | 3 +- tools/perf/ui/stdio/hist.c | 2 +- tools/perf/ui/tui/setup.c | 1 + tools/perf/ui/tui/util.c | 2 +- tools/perf/util/Build | 5 ++ tools/perf/util/annotate.c | 13 ++--- tools/perf/util/arm-spe.c | 2 +- tools/perf/util/auxtrace.c | 11 ++--- tools/perf/util/bpf-loader.c | 3 +- tools/perf/util/build-id.c | 1 + tools/perf/util/call-path.c | 5 +- tools/perf/util/callchain.c | 12 ++--- tools/perf/util/cgroup.c | 4 +- tools/perf/util/comm.c | 2 +- tools/perf/util/config.c | 3 +- tools/perf/util/counts.c | 2 +- tools/perf/util/cpumap.c | 2 +- tools/perf/util/cputopo.c | 5 +- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 1 + tools/perf/util/cs-etm.c | 8 ++-- tools/perf/util/data-convert-bt.c | 4 +- tools/perf/util/data.c | 3 +- tools/perf/util/db-export.c | 7 +-- tools/perf/util/debug.c | 1 + tools/perf/util/demangle-java.c | 3 +- tools/perf/util/dso.c | 5 +- tools/perf/util/dwarf-aux.c | 2 +- tools/perf/util/env.c | 11 +++-- tools/perf/util/event.c | 3 +- tools/perf/util/evlist.c | 2 +- tools/perf/util/evsel.c | 4 +- tools/perf/util/get_current_dir_name.c | 6 +-- tools/perf/util/get_current_dir_name.h | 8 ++++ tools/perf/util/header.c | 8 ++-- tools/perf/util/help-unknown-cmd.c | 2 + tools/perf/util/hist.c | 20 ++++---- tools/perf/util/intel-bts.c | 7 ++- .../perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 +- tools/perf/util/intel-pt.c | 15 +++--- tools/perf/util/jitdump.c | 7 ++- tools/perf/util/llvm-utils.c | 4 +- tools/perf/util/machine.c | 6 +-- tools/perf/util/map.c | 9 ++-- tools/perf/util/mem2node.c | 2 +- tools/perf/util/metricgroup.c | 10 ++-- tools/perf/util/mmap.c | 1 + tools/perf/util/namespaces.c | 3 +- tools/perf/util/namespaces.h | 4 ++ tools/perf/util/ordered-events.c | 6 +-- tools/perf/util/parse-branch-options.c | 2 +- tools/perf/util/parse-events.c | 3 +- tools/perf/util/parse-events.y | 2 - tools/perf/util/parse-regs-options.c | 8 +++- tools/perf/util/pmu.c | 4 +- tools/perf/util/probe-event.c | 55 ++++++++++------------ tools/perf/util/probe-file.c | 2 +- tools/perf/util/probe-finder.c | 2 +- tools/perf/util/pstack.c | 2 +- tools/perf/util/python-ext-sources | 1 + tools/perf/util/s390-cpumsf.c | 11 ++--- tools/perf/util/session.c | 7 ++- tools/perf/util/setns.c | 4 +- tools/perf/util/srccode.c | 11 +++-- tools/perf/util/srcline.c | 2 +- tools/perf/util/stat-shadow.c | 3 +- tools/perf/util/stat.c | 3 +- tools/perf/util/strbuf.c | 3 +- tools/perf/util/strfilter.c | 3 +- tools/perf/util/strlist.c | 2 +- tools/perf/util/svghelper.c | 2 +- tools/perf/util/symbol-elf.c | 18 +++---- tools/perf/util/symbol-minimal.c | 3 +- tools/perf/util/symbol.c | 1 + tools/perf/util/syscalltbl.c | 2 +- tools/perf/util/target.c | 2 +- tools/perf/util/thread-stack.c | 3 +- tools/perf/util/thread.c | 6 +-- tools/perf/util/thread_map.c | 4 +- tools/perf/util/trace-event-info.c | 1 + tools/perf/util/trace-event-scripting.c | 2 +- tools/perf/util/unwind-libdw.c | 1 + tools/perf/util/unwind-libunwind-local.c | 3 +- tools/perf/util/usage.c | 3 ++ tools/perf/util/util.h | 17 ------- tools/perf/util/values.c | 2 +- tools/perf/util/vdso.c | 1 + tools/perf/util/xyarray.c | 2 +- 147 files changed, 375 insertions(+), 279 deletions(-) create mode 100644 tools/include/linux/zalloc.h create mode 100644 tools/lib/zalloc.c create mode 100644 tools/perf/util/get_current_dir_name.h
Test results:
The first ones are container based builds of tools/perf with and without libelf support. Where clang is available, it is also used to build perf with/without libelf, and building with LIBCLANGLLVM=1 (built-in clang) with gcc and clang when clang and its devel libraries are installed.
The objtool and samples/bpf/ builds are disabled now that I'm switching from using the sources in a local volume to fetching them from a http server to build it inside the container, to make it easier to build in a container cluster. Those will come back later.
Several are cross builds, the ones with -x-ARCH and the android one, and those may not have all the features built, due to lack of multi-arch devel packages, available and being used so far on just a few, like debian:experimental-x-{arm64,mipsel}.
The 'perf test' one will perform a variety of tests exercising tools/perf/util/, tools/lib/{bpf,traceevent,etc}, as well as run perf commands with a variety of command line event specifications to then intercept the sys_perf_event syscall to check that the perf_event_attr fields are set up as expected, among a variety of other unit tests.
Then there is the 'make -C tools/perf build-test' ones, that build tools/perf/ with a variety of feature sets, exercising the build with an incomplete set of features as well as with a complete one. It is planned to have it run on each of the containers mentioned above, using some container orchestration infrastructure. Get in contact if interested in helping having this in place.
The 'perf test bpf' test is about rlimit(MEMLOCK), bump it a to 128K from the default 64K and it'll work. Next pull req will have auto-adjustment for 'perf test' and 'perf trace', where BPF programs creating maps are also failing.
$ export PERF_TARBALL=http://192.168.124.1/perf/perf-5.2.0.tar.xz $ dm 1 alpine:3.4 : Ok gcc (Alpine 5.3.0) 5.3.0, clang version 3.8.0 (tags/RELEASE_380/final) 2 alpine:3.5 : Ok gcc (Alpine 6.2.1) 6.2.1 20160822, clang version 3.8.1 (tags/RELEASE_381/final) 3 alpine:3.6 : Ok gcc (Alpine 6.3.0) 6.3.0, clang version 4.0.0 (tags/RELEASE_400/final) 4 alpine:3.7 : Ok gcc (Alpine 6.4.0) 6.4.0, Alpine clang version 5.0.0 (tags/RELEASE_500/final) (based on LLVM 5.0.0) 5 alpine:3.8 : Ok gcc (Alpine 6.4.0) 6.4.0, Alpine clang version 5.0.1 (tags/RELEASE_501/final) (based on LLVM 5.0.1) 6 alpine:3.9 : Ok gcc (Alpine 8.3.0) 8.3.0, Alpine clang version 5.0.1 (tags/RELEASE_502/final) (based on LLVM 5.0.1) 7 alpine:3.10 : Ok gcc (Alpine 8.3.0) 8.3.0, Alpine clang version 8.0.0 (tags/RELEASE_800/final) (based on LLVM 8.0.0) 8 alpine:edge : Ok gcc (Alpine 8.3.0) 8.3.0, Alpine clang version 7.0.1 (tags/RELEASE_701/final) (based on LLVM 7.0.1) 9 amazonlinux:1 : Ok gcc (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2), clang version 3.6.2 (tags/RELEASE_362/final) 10 amazonlinux:2 : Ok gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5), clang version 7.0.1 (Amazon Linux 2 7.0.1-1.amzn2.0.2) 11 android-ndk:r12b-arm : Ok arm-linux-androideabi-gcc (GCC) 4.9.x 20150123 (prerelease) 12 android-ndk:r15c-arm : Ok arm-linux-androideabi-gcc (GCC) 4.9.x 20150123 (prerelease) 13 centos:5 : Ok gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-55) 14 centos:6 : Ok gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-23) 15 centos:7 : Ok gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36), clang version 3.4.2 (tags/RELEASE_34/dot2-final) 16 clearlinux:latest : Ok gcc (Clear Linux OS for Intel Architecture) 9.1.1 20190628 gcc-9-branch@272773, clang version 8.0.0 (tags/RELEASE_800/final) 17 debian:8 : Ok gcc (Debian 4.9.2-10+deb8u2) 4.9.2, Debian clang version 3.5.0-10 (tags/RELEASE_350/final) (based on LLVM 3.5.0) 18 debian:9 : Ok gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, clang version 3.8.1-24 (tags/RELEASE_381/final) 19 debian:experimental : Ok gcc (Debian 8.3.0-7) 8.3.0, clang version 7.0.1-8 (tags/RELEASE_701/final) 20 debian:experimental-x-arm64 : Ok aarch64-linux-gnu-gcc (Debian 8.3.0-7) 8.3.0 21 debian:experimental-x-mips : Ok mips-linux-gnu-gcc (Debian 8.3.0-7) 8.3.0 22 debian:experimental-x-mips64 : Ok mips64-linux-gnuabi64-gcc (Debian 8.3.0-7) 8.3.0 23 debian:experimental-x-mipsel : Ok mipsel-linux-gnu-gcc (Debian 8.3.0-7) 8.3.0 24 fedora:20 : Ok gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-7), clang version 3.4.2 (tags/RELEASE_34/dot2-final) 25 fedora:22 : Ok gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6), clang version 3.5.0 (tags/RELEASE_350/final) 26 fedora:23 : Ok gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6), clang version 3.7.0 (tags/RELEASE_370/final) 27 fedora:24 : Ok gcc (GCC) 6.3.1 20161221 (Red Hat 6.3.1-1), clang version 3.8.1 (tags/RELEASE_381/final) 28 fedora:24-x-ARC-uClibc : Ok arc-linux-gcc (ARCompact ISA Linux uClibc toolchain 2017.09-rc2) 7.1.1 20170710 29 fedora:25 : Ok gcc (GCC) 6.4.1 20170727 (Red Hat 6.4.1-1), clang version 3.9.1 (tags/RELEASE_391/final) 30 fedora:26 : Ok gcc (GCC) 7.3.1 20180130 (Red Hat 7.3.1-2), clang version 4.0.1 (tags/RELEASE_401/final) 31 fedora:27 : Ok gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-6), clang version 5.0.2 (tags/RELEASE_502/final) 32 fedora:28 : Ok gcc (GCC) 8.3.1 20190223 (Red Hat 8.3.1-2), clang version 6.0.1 (tags/RELEASE_601/final) 33 fedora:29 : Ok gcc (GCC) 8.3.1 20190223 (Red Hat 8.3.1-2), clang version 7.0.1 (Fedora 7.0.1-6.fc29) 34 fedora:30 : Ok gcc (GCC) 9.1.1 20190503 (Red Hat 9.1.1-1), clang version 8.0.0 (Fedora 8.0.0-1.fc30) 35 fedora:30-x-ARC-glibc : Ok arc-linux-gcc (ARC HS GNU/Linux glibc toolchain 2019.03-rc1) 8.3.1 20190225 36 fedora:30-x-ARC-uClibc : Ok arc-linux-gcc (ARCv2 ISA Linux uClibc toolchain 2019.03-rc1) 8.3.1 20190225 37 fedora:31 : Ok gcc (GCC) 9.1.1 20190605 (Red Hat 9.1.1-2), clang version 8.0.0 (Fedora 8.0.0-3.fc31) 38 fedora:rawhide : Ok gcc (GCC) 9.1.1 20190605 (Red Hat 9.1.1-2), clang version 8.0.0 (Fedora 8.0.0-3.fc31) 39 gentoo-stage3-amd64:latest : Ok gcc (Gentoo 8.3.0-r1 p1.1) 8.3.0 40 mageia:5 : Ok gcc (GCC) 4.9.2, clang version 3.5.2 (tags/RELEASE_352/final) 41 mageia:6 : Ok gcc (Mageia 5.5.0-1.mga6) 5.5.0, clang version 3.9.1 (tags/RELEASE_391/final) 42 mageia:7 : Ok gcc (Mageia 8.3.1-0.20190524.1.mga7) 8.3.1 20190524, clang version 8.0.0 (Mageia 8.0.0-1.mga7) 43 manjaro:latest : Ok gcc (GCC) 9.1.0, clang version 8.0.0 (tags/RELEASE_800/final) 44 opensuse:15.0 : Ok gcc (SUSE Linux) 7.4.1 20190424 [gcc-7-branch revision 270538], clang version 5.0.1 (tags/RELEASE_501/final 312548) 45 opensuse:15.1 : Ok gcc (SUSE Linux) 7.4.0, clang version 7.0.1 (tags/RELEASE_701/final 349238) 46 opensuse:42.3 : Ok gcc (SUSE Linux) 4.8.5, clang version 3.8.0 (tags/RELEASE_380/final 262553) 47 opensuse:tumbleweed : Ok gcc (SUSE Linux) 9.1.1 20190611 [gcc-9-branch revision 272147], clang version 8.0.0 (tags/RELEASE_800/final 356365) 48 oraclelinux:6 : Ok gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-23.0.1) 49 oraclelinux:7 : Ok gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36.0.1), clang version 3.4.2 (tags/RELEASE_34/dot2-final) 50 ubuntu:12.04 : Ok gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 51 ubuntu:14.04 : Ok gcc (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4, Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4) 52 ubuntu:16.04 : Ok gcc (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609, clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final) 53 ubuntu:16.04-x-arm : Ok arm-linux-gnueabihf-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 54 ubuntu:16.04-x-arm64 : Ok aarch64-linux-gnu-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 55 ubuntu:16.04-x-powerpc : Ok powerpc-linux-gnu-gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 56 ubuntu:16.04-x-powerpc64 : Ok powerpc64-linux-gnu-gcc (Ubuntu/IBM 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 57 ubuntu:16.04-x-powerpc64el : Ok powerpc64le-linux-gnu-gcc (Ubuntu/IBM 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 58 ubuntu:16.04-x-s390 : Ok s390x-linux-gnu-gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 59 ubuntu:18.04 : Ok gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0, clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final) 60 ubuntu:18.04-x-arm : Ok arm-linux-gnueabihf-gcc (Ubuntu/Linaro 7.4.0-1ubuntu1~18.04.1) 7.4.0 61 ubuntu:18.04-x-arm64 : Ok aarch64-linux-gnu-gcc (Ubuntu/Linaro 7.4.0-1ubuntu1~18.04.1) 7.4.0 62 ubuntu:18.04-x-m68k : Ok m68k-linux-gnu-gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 63 ubuntu:18.04-x-powerpc : Ok powerpc-linux-gnu-gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 64 ubuntu:18.04-x-powerpc64 : Ok powerpc64-linux-gnu-gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 65 ubuntu:18.04-x-powerpc64el : Ok powerpc64le-linux-gnu-gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 66 ubuntu:18.04-x-riscv64 : Ok riscv64-linux-gnu-gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 67 ubuntu:18.04-x-s390 : Ok s390x-linux-gnu-gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 68 ubuntu:18.04-x-sh4 : Ok sh4-linux-gnu-gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 69 ubuntu:18.04-x-sparc64 : Ok sparc64-linux-gnu-gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 70 ubuntu:18.10 : Ok gcc (Ubuntu 8.3.0-6ubuntu1~18.10.1) 8.3.0, clang version 7.0.0-3 (tags/RELEASE_700/final) 71 ubuntu:19.04 : Ok gcc (Ubuntu 8.3.0-6ubuntu1) 8.3.0, clang version 8.0.0-3 (tags/RELEASE_800/final) 72 ubuntu:19.04-x-alpha : Ok alpha-linux-gnu-gcc (Ubuntu 8.3.0-6ubuntu1) 8.3.0 73 ubuntu:19.04-x-arm64 : Ok aarch64-linux-gnu-gcc (Ubuntu/Linaro 8.3.0-6ubuntu1) 8.3.0 74 ubuntu:19.04-x-hppa : Ok hppa-linux-gnu-gcc (Ubuntu 8.3.0-6ubuntu1) 8.3.0 75 ubuntu:19.10 : Ok gcc (Ubuntu 8.3.0-14ubuntu1) 8.3.0, clang version 8.0.1-+rc1-1~exp1 (tags/RELEASE_801/rc1) $
# uname -a
Linux quaco 5.2.0-rc7+ #4 SMP Sat Jul 6 14:43:41 -03 2019 x86_64 x86_64 x86_64 GNU/Linux
# git log --oneline -1
323fd749821d perf intel-pt: Fix potential NULL pointer dereference found by the smatch tool
# perf version --build-options
perf version 5.2.g323fd749821d
dwarf: [ on ] # HAVE_DWARF_SUPPORT
dwarf_getlocations: [ on ] # HAVE_DWARF_GETLOCATIONS_SUPPORT
glibc: [ on ] # HAVE_GLIBC_SUPPORT
gtk2: [ on ] # HAVE_GTK2_SUPPORT
syscall_table: [ on ] # HAVE_SYSCALL_TABLE_SUPPORT
libbfd: [ on ] # HAVE_LIBBFD_SUPPORT
libelf: [ on ] # HAVE_LIBELF_SUPPORT
libnuma: [ on ] # HAVE_LIBNUMA_SUPPORT
numa_num_possible_cpus: [ on ] # HAVE_LIBNUMA_SUPPORT
libperl: [ on ] # HAVE_LIBPERL_SUPPORT
libpython: [ on ] # HAVE_LIBPYTHON_SUPPORT
libslang: [ on ] # HAVE_SLANG_SUPPORT
libcrypto: [ on ] # HAVE_LIBCRYPTO_SUPPORT
libunwind: [ on ] # HAVE_LIBUNWIND_SUPPORT
libdw-dwarf-unwind: [ on ] # HAVE_DWARF_SUPPORT
zlib: [ on ] # HAVE_ZLIB_SUPPORT
lzma: [ on ] # HAVE_LZMA_SUPPORT
get_cpuid: [ on ] # HAVE_AUXTRACE_SUPPORT
bpf: [ on ] # HAVE_LIBBPF_SUPPORT
aio: [ on ] # HAVE_AIO_SUPPORT
zstd: [ on ] # HAVE_ZSTD_SUPPORT
# perf test
1: vmlinux symtab matches kallsyms : Ok
2: Detect openat syscall event : Ok
3: Detect openat syscall event on all cpus : Ok
4: Read samples using the mmap interface : Ok
5: Test data source output : Ok
6: Parse event definition strings : Ok
7: Simple expression parser : Ok
8: PERF_RECORD_* events & perf_sample fields : Ok
9: Parse perf pmu format : Ok
10: DSO data read : Ok
11: DSO data cache : Ok
12: DSO data reopen : Ok
13: Roundtrip evsel->name : Ok
14: Parse sched tracepoints fields : Ok
15: syscalls:sys_enter_openat event fields : Ok
16: Setup struct perf_event_attr : Ok
17: Match and link multiple hists : Ok
18: 'import perf' in python : Ok
19: Breakpoint overflow signal handler : Ok
20: Breakpoint overflow sampling : Ok
21: Breakpoint accounting : Ok
22: Watchpoint :
22.1: Read Only Watchpoint : Skip
22.2: Write Only Watchpoint : Ok
22.3: Read / Write Watchpoint : Ok
22.4: Modify Watchpoint : Ok
23: Number of exit events of a simple workload : Ok
24: Software clock events period values : Ok
25: Object code reading : Ok
26: Sample parsing : Ok
27: Use a dummy software event to keep tracking : Ok
28: Parse with no sample_id_all bit set : Ok
29: Filter hist entries : Ok
30: Lookup mmap thread : Ok
31: Share thread mg : Ok
32: Sort output of hist entries : Ok
33: Cumulate child hist entries : Ok
34: Track with sched_switch : Ok
35: Filter fds with revents mask in a fdarray : Ok
36: Add fd to a fdarray, making it autogrow : Ok
37: kmod_path__parse : Ok
38: Thread map : Ok
39: LLVM search and compile :
39.1: Basic BPF llvm compile : Ok
39.2: kbuild searching : Ok
39.3: Compile source for BPF prologue generation : Ok
39.4: Compile source for BPF relocation : Ok
40: Session topology : Ok
41: BPF filter :
41.1: Basic BPF filtering : Skip
41.2: BPF pinning : Skip
41.3: BPF prologue generation : Skip
41.4: BPF relocation checker : Skip
42: Synthesize thread map : Ok
43: Remove thread map : Ok
44: Synthesize cpu map : Ok
45: Synthesize stat config : Ok
46: Synthesize stat : Ok
47: Synthesize stat round : Ok
48: Synthesize attr update : Ok
49: Event times : Ok
50: Read backward ring buffer : Ok
51: Print cpu map : Ok
52: Probe SDT events : Ok
53: is_printable_array : Ok
54: Print bitmap : Ok
55: perf hooks : Ok
56: builtin clang support : Skip (not compiled in)
57: unit_number__scnprintf : Ok
58: mem2node : Ok
59: time utils : Ok
60: map_groups__merge_in : Ok
61: x86 rdpmc : Ok
62: Convert perf time to TSC : Ok
63: DWARF unwind : Ok
64: x86 instruction decoder - new instructions : Ok
65: Intel PT packet decoder : Ok
66: x86 bp modify : Ok
67: probe libc's inet_pton & backtrace it with ping : Ok
68: Use vfs_getname probe to get syscall args filenames : Ok
69: Add vfs_getname probe to get syscall args filenames : Ok
70: Check open filename arg using perf trace + vfs_getname: Ok
71: Zstd perf.data compression/decompression : Ok $ make -C tools/perf build-test | tee /wb/build-test
make: Entering directory '/home/acme/git/perf/tools/perf'
- tarpkg: ./tests/perf-targz-src-pkg .
make_no_libbpf_O: make NO_LIBBPF=1
make_static_O: make LDFLAGS=-static
make_util_map_o_O: make util/map.o
make_no_libdw_dwarf_unwind_O: make NO_LIBDW_DWARF_UNWIND=1
make_clean_all_O: make clean all
make_doc_O: make doc
make_no_libperl_O: make NO_LIBPERL=1
make_install_O: make install
make_no_scripts_O: make NO_LIBPYTHON=1 NO_LIBPERL=1
make_with_babeltrace_O: make LIBBABELTRACE=1
make_install_prefix_O: make install prefix=/tmp/krava
make_no_auxtrace_O: make NO_AUXTRACE=1
make_no_backtrace_O: make NO_BACKTRACE=1
make_cscope_O: make cscope
make_tags_O: make tags
make_util_pmu_bison_o_O: make util/pmu-bison.o
make_no_libunwind_O: make NO_LIBUNWIND=1
make_no_libpython_O: make NO_LIBPYTHON=1
make_no_slang_O: make NO_SLANG=1
make_install_bin_O: make install-bin
make_install_prefix_slash_O: make install prefix=/tmp/krava/
make_perf_o_O: make perf.o
make_no_ui_O: make NO_NEWT=1 NO_SLANG=1 NO_GTK2=1
make_no_libnuma_O: make NO_LIBNUMA=1
make_no_gtk2_O: make NO_GTK2=1
make_minimal_O: make NO_LIBPERL=1 NO_LIBPYTHON=1 NO_NEWT=1 NO_GTK2=1 NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=1 NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1 NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 NO_LIBBPF=1 NO_LIBCRYPTO=1 NO_SDT=1 NO_JVMTI=1 NO_LIBZSTD=1
make_with_clangllvm_O: make LIBCLANGLLVM=1
make_no_libbionic_O: make NO_LIBBIONIC=1
make_no_libelf_O: make NO_LIBELF=1
make_pure_O: make
make_no_newt_O: make NO_NEWT=1
make_no_libaudit_O: make NO_LIBAUDIT=1
make_help_O: make help
make_debug_O: make DEBUG=1
make_no_demangle_O: make NO_DEMANGLE=1
OK
make: Leaving directory '/home/acme/git/perf/tools/perf'
$Arnaldo Carvalho de Melo
maintainerPATCH 1/25 perf test mmap-thread-lookup: Initialize variable to suppress memory sanitizer warning
From: Numfor Mbiziwo-Tiapo <[email protected]>
Running the 'perf test' command after building perf with a memory sanitizer causes a warning that says:
WARNING: MemorySanitizer: use-of-uninitialized-value... in mmap-thread-lookup.c
Initializing the go variable to 0 silences this harmless warning.
Committer warning:
This was harmless, just a simple test writing whatever was at that sizeof(int) memory area just to signal another thread blocked reading that file created with pipe(). Initialize it tho so that we don't get this warning.
--- tools/perf/tests/mmap-thread-lookup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/mmap-thread-lookup.c +1 -1
@@ -53,7 +53,7 @@ static void *thread_fn(void *arg) {struct thread_data *td = arg;ssize_t ret; -int go; +int go =0 ;if (thread_init (td))return NULL ;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 2/25 perf stat: Fix use-after-freed pointer detected by the smatch tool
In reply to Arnaldo Carvalho de MeloFrom: Leo Yan <[email protected]>
Based on the following report from Smatch, fix the use-after-freed pointer.
tools/perf/builtin-stat.c:1353 add_default_attributes() warn: passing freed memory 'str'.
The pointer 'str' has been freed but later it is still passed into the function parse_events_print_error(). This patch fixes this use-after-freed issue.
--- tools/perf/builtin-stat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-stat.c +1 -1
@@ -1349,8 +1349,8 @@ static int add_default_attributes(void)fprintf (stderr,"Cannot set up top down events %s: %d\n" , str, err); -free (str);parse_events_print_error (&errinfo, str); +free (str);return -1 ; } }else {
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 3/25 perf top: Fix potential NULL pointer dereference detected by the smatch tool
In reply to Arnaldo Carvalho de MeloFrom: Leo Yan <[email protected]>
Based on the following report from Smatch, fix the potential NULL pointer dereference check.
tools/perf/builtin-top.c:109
perf_top__parse_source() warn: variable dereferenced before check 'he' (see line 103)
tools/perf/builtin-top.c:233
perf_top__show_details() warn: variable dereferenced before check 'he' (see line 228)
tools/perf/builtin-top.c
101 static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he)
102 {
103 struct perf_evsel *evsel = hists_to_evsel(he->hists);
^^^^
104 struct symbol *sym;
105 struct annotation *notes;
106 struct map *map;
107 int err = -1;
108
109 if (!he || !he->ms.sym)
110 return -1;This patch moves the values assignment after validating pointer 'he'.
--- tools/perf/builtin-top.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
tools/perf/builtin-top.c +6 -2
@@ -101,7 +101,7 @@ static void perf_top__resize(struct perf_top *top)static int perf_top__parse_source (struct perf_top *top,struct hist_entry *he) { -struct perf_evsel *evsel =hists_to_evsel (he->hists); +struct perf_evsel *evsel;struct symbol *sym;struct annotation *notes;struct map *map;
@@ -110,6 +110,8 @@ static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he)if (!he || !he->ms.sym)return -1 ; + evsel =hists_to_evsel (he->hists); + sym = he->ms.sym; map = he->ms.map;
@@ -226,7 +228,7 @@ static void perf_top__record_precise_ip(struct perf_top *top,static void perf_top__show_details (struct perf_top *top) {struct hist_entry *he = top->sym_filter_entry; -struct perf_evsel *evsel =hists_to_evsel (he->hists); +struct perf_evsel *evsel;struct annotation *notes;struct symbol *symbol;int more;
@@ -234,6 +236,8 @@ static void perf_top__show_details(struct perf_top *top)if (!he)return ; + evsel =hists_to_evsel (he->hists); + symbol = he->ms.sym; notes =symbol__annotation (symbol);
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 4/25 perf annotate: Fix dereferencing freed memory found by the smatch tool
In reply to Arnaldo Carvalho de MeloFrom: Leo Yan <[email protected]>
Based on the following report from Smatch, fix the potential dereferencing freed memory check.
tools/perf/util/annotate.c:1125
disasm_line__parse() error: dereferencing freed memory 'namep'
tools/perf/util/annotate.c
1100 static int disasm_line__parse(char *line, const char **namep, char **rawp)
1101 {
1102 char tmp, *name = ltrim(line);[...]
1114 *namep = strdup(name); 1115 1116 if (*namep == NULL) 1117 goto out_free_name;
[...]
1124 out_free_name:
1125 free((void *)namep);
^^^^^
1126 *namep = NULL;
^^^^^^
1127 return -1;
1128 }If strdup() fails to allocate memory space for *namep, we don't need to free memory with pointer 'namep', which is resident in data structure disasm_line::ins::name; and *namep is NULL pointer for this failure, so it's pointless to assign NULL to *namep again.
Committer note:
Freeing namep, which is the address of the first entry of the 'struct ins' that is the first member of struct disasm_line would in fact free that disasm_line instance, if it was allocated via malloc/calloc, which, later, would a dereference of freed memory.
--- tools/perf/util/annotate.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
tools/perf/util/annotate.c +2 -4
@@ -1119,16 +1119,14 @@ static int disasm_line__parse(char *line, const char **namep, char **rawp) *namep =strdup (name);if (*namep ==NULL ) - goto out_free_name; + goto out; (*rawp)[0 ] = tmp; *rawp =skip_spaces (*rawp);return 0 ; -out_free_name: -free ((void *)namep); - *namep =NULL ; +out:return -1 ; }
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 5/25 perf trace: Fix potential NULL pointer dereference found by the smatch tool
In reply to Arnaldo Carvalho de MeloFrom: Leo Yan <[email protected]>
Based on the following report from Smatch, fix the potential NULL pointer dereference check.
tools/perf/builtin-trace.c:1044
thread_trace__new() error: we previously assumed 'ttrace' could be null (see line 1041).
tools/perf/builtin-trace.c
1037 static struct thread_trace *thread_trace__new(void)
1038 {
1039 struct thread_trace *ttrace = zalloc(sizeof(struct thread_trace));
1040
1041 if (ttrace)
1042 ttrace->files.max = -1;
1043
1044 ttrace->syscall_stats = intlist__new(NULL);
^^^^^^^^
1045
1046 return ttrace;
1047 }--- tools/perf/builtin-trace.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/builtin-trace.c +3 -3
@@ -1038,10 +1038,10 @@ static struct thread_trace *thread_trace__new(void) {struct thread_trace *ttrace =zalloc (sizeof (struct thread_trace )); -if (ttrace) +if (ttrace) { ttrace->files.max =-1 ; - - ttrace->syscall_stats =intlist__new (NULL ); + ttrace->syscall_stats =intlist__new (NULL ); + }return ttrace; }
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 6/25 perf map: Fix potential NULL pointer dereference found by smatch tool
In reply to Arnaldo Carvalho de MeloFrom: Leo Yan <[email protected]>
Based on the following report from Smatch, fix the potential NULL pointer dereference check.
tools/perf/util/map.c:479
map__fprintf_srccode() error: we previously assumed 'state' could be null (see line 466)
tools/perf/util/map.c
465 /* Avoid redundant printing */
466 if (state &&
467 state->srcfile &&
468 !strcmp(state->srcfile, srcfile) &&
469 state->line == line) {
470 free(srcfile);
471 return 0;
472 }
473
474 srccode = find_sourceline(srcfile, line, &len);
475 if (!srccode)
476 goto out_free_line;
477
478 ret = fprintf(fp, "|%-8d %.*s", line, len, srccode);
479 state->srcfile = srcfile;
^^^^^^^
480 state->line = line;
^^^^^^^This patch validates 'state' pointer before access its elements.
--- tools/perf/util/map.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/perf/util/map.c +5 -2
@@ -476,8 +476,11 @@ int map__fprintf_srccode(struct map *map, u64 addr, goto out_free_line; ret =fprintf (fp,"|%-8d %.*s" , line, len, srccode); - state->srcfile = srcfile; - state->line = line; + +if (state) { + state->srcfile = srcfile; + state->line = line; + }return ret; out_free_line:
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 7/25 perf inject: The tool->read() call may pass a NULL evsel, handle it
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Check first, as machines__deliver_event() may have perf_evlist__id2evsel() returning NULL.
This was found while checking a report from Leo Yan that used the smatch tool to find places where a pointer is checked before use and then, later in the same function gets used without checking.
--- tools/perf/builtin-inject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-inject.c +1 -1
@@ -224,7 +224,7 @@ static int perf_event__repipe_sample(struct perf_tool *tool, struct perf_evsel *evsel, struct machine *machine) { -if (evsel->handler) { +if (evsel && evsel->handler) {inject_handler f = evsel->handler;return f (tool, event, sample, evsel, machine); }
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 8/25 perf session: Fix potential NULL pointer dereference found by the smatch tool
In reply to Arnaldo Carvalho de MeloFrom: Leo Yan <[email protected]>
Based on the following report from Smatch, fix the potential NULL pointer dereference check.
tools/perf/util/session.c:1252
dump_read() error: we previously assumed 'evsel' could be null (see line 1249)
tools/perf/util/session.c
1240 static void dump_read(struct perf_evsel *evsel, union perf_event *event)
1241 {
1242 struct read_event *read_event = &event->read;
1243 u64 read_format;
1244
1245 if (!dump_trace)
1246 return;
1247
1248 printf(": %d %d %s %" PRIu64 "\n", event->read.pid, event->read.tid,
1249 evsel ? perf_evsel__name(evsel) : "FAIL",
1250 event->read.value);
1251
1252 read_format = evsel->attr.read_format;
^^^^^^^'evsel' could be NULL pointer, for this case this patch directly bails out without dumping read_event.
--- tools/perf/util/session.c | 3 +++ 1 file changed, 3 insertions(+)
tools/perf/util/session.c +3 -0
@@ -1249,6 +1249,9 @@ static void dump_read(struct perf_evsel *evsel, union perf_event *event) evsel ?perf_evsel__name (evsel) :"FAIL" , event->read.value); +if (!evsel) +return ; + read_format = evsel->attr.read_format;if (read_format &PERF_FORMAT_TOTAL_TIME_ENABLED )
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 9/25 perf evsel: perf_evsel__name(NULL) is valid, no need to check evsel
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
It'll return "unknown", no need to open code it.
--- tools/perf/builtin-report.c | 2 +- tools/perf/util/session.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-report.c +1 -1
@@ -298,7 +298,7 @@ static int process_read_event(struct perf_tool *tool, struct report *rep = container_of(tool, struct report, tool);if (rep->show_threads) { -const char *name = evsel ?perf_evsel__name (evsel) :"unknown" ; +const char *name =perf_evsel__name (evsel); int err = perf_read_values_add_value(&rep->show_threads_values, event->read.pid, event->read.tid, evsel->idx,
tools/perf/util/session.c +1 -1
@@ -1246,7 +1246,7 @@ static void dump_read(struct perf_evsel *evsel, union perf_event *event)return ;printf (": %d %d %s %" PRIu64"\n" , event->read.pid, event->read.tid, - evsel ?perf_evsel__name (evsel) :"FAIL" , +perf_evsel__name (evsel), event->read.value);if (!evsel)
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 10/25 perf tools: Add missing headers, mostly stdlib.h
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Part of the erosion of util/util.h, that will lose its include stdlib.h, we need to add it to places where it is needed but was getting it indirectly.
--- tools/perf/arch/common.c | 1 + tools/perf/arch/powerpc/util/perf_regs.c | 2 ++ tools/perf/arch/s390/util/header.c | 1 + tools/perf/builtin-config.c | 1 + tools/perf/builtin-help.c | 1 + tools/perf/tests/llvm.c | 1 + tools/perf/tests/sample-parsing.c | 1 + tools/perf/tests/vmlinux-kallsyms.c | 1 + tools/perf/ui/browser.h | 1 + tools/perf/ui/browsers/map.c | 1 + tools/perf/ui/tui/setup.c | 1 + tools/perf/ui/tui/util.c | 2 +- tools/perf/util/cputopo.c | 1 + tools/perf/util/db-export.c | 1 + tools/perf/util/debug.c | 1 + tools/perf/util/demangle-java.c | 3 ++- tools/perf/util/dwarf-aux.c | 2 +- tools/perf/util/env.c | 1 + tools/perf/util/parse-branch-options.c | 2 +- tools/perf/util/parse-regs-options.c | 8 ++++++-- tools/perf/util/strbuf.c | 1 + tools/perf/util/symbol-elf.c | 1 + tools/perf/util/symbol-minimal.c | 1 + tools/perf/util/target.c | 2 +- tools/perf/util/thread-stack.c | 1 + tools/perf/util/usage.c | 3 +++ 26 files changed, 35 insertions(+), 7 deletions(-)
tools/perf/arch/common.c +1 -0
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0 #include <stdio.h> +#include <stdlib.h> #include "common.h" #include "../util/env.h" #include "../util/util.h"
tools/perf/arch/powerpc/util/perf_regs.c +2 -0
@@ -8,6 +8,8 @@#include "../../util/perf_regs.h" #include "../../util/debug.h" +#include <linux/kernel.h> +const struct sample_reg sample_reg_masks[] = {SMPL_REG (r0,PERF_REG_POWERPC_R0 ),SMPL_REG (r1,PERF_REG_POWERPC_R1 ),
tools/perf/arch/s390/util/header.c +1 -0
@@ -12,6 +12,7 @@#include <stdio.h> #include <string.h> #include <linux/ctype.h> +#include <linux/kernel.h> #include "../../util/header.h" #include "../../util/util.h"
tools/perf/builtin-config.c +1 -0
@@ -15,6 +15,7 @@#include "util/debug.h" #include "util/config.h" #include <linux/string.h> +#include <stdlib.h> static bool use_system_config, use_user_config;
tools/perf/builtin-help.c +1 -0
@@ -16,6 +16,7 @@#include <linux/kernel.h> #include <errno.h> #include <stdio.h> +#include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h>
tools/perf/tests/llvm.c +1 -0
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0 #include <stdio.h> +#include <stdlib.h> #include <bpf/libbpf.h> #include <util/llvm-utils.h> #include <util/cache.h>
tools/perf/tests/sample-parsing.c +1 -0
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include <stdbool.h> #include <inttypes.h> +#include <stdlib.h> #include <linux/bitops.h> #include <linux/kernel.h> #include <linux/types.h>
tools/perf/tests/vmlinux-kallsyms.c +1 -0
@@ -3,6 +3,7 @@#include <linux/rbtree.h> #include <inttypes.h> #include <string.h> +#include <stdlib.h> #include "map.h" #include "symbol.h" #include "util.h"
tools/perf/ui/browser.h +1 -0
@@ -4,6 +4,7 @@#include <linux/types.h> #include <stdarg.h> +#include <sys/types.h> #define HE_COLORSET_TOP 50#define HE_COLORSET_MEDIUM 51
tools/perf/ui/browsers/map.c +1 -0
@@ -2,6 +2,7 @@#include <elf.h> #include <inttypes.h> #include <sys/ttydefaults.h> +#include <stdlib.h> #include <string.h> #include <linux/bitops.h> #include "../../util/util.h"
tools/perf/ui/tui/setup.c +1 -0
@@ -2,6 +2,7 @@#include <errno.h> #include <signal.h> #include <stdbool.h> +#include <stdlib.h> #include <linux/kernel.h> #ifdef HAVE_BACKTRACE_SUPPORT #include <execinfo.h>
tools/perf/ui/tui/util.c +1 -1
@@ -1,8 +1,8 @@// SPDX-License-Identifier: GPL-2.0 -#include "../../util/util.h" #include <signal.h> #include <stdbool.h> #include <string.h> +#include <stdlib.h> #include <sys/ttydefaults.h> #include "../../util/cache.h"
tools/perf/util/cputopo.c +1 -0
@@ -2,6 +2,7 @@#include <sys/param.h> #include <sys/utsname.h> #include <inttypes.h> +#include <stdlib.h> #include <api/fs/fs.h> #include "cputopo.h"
tools/perf/util/db-export.c +1 -0
@@ -5,6 +5,7 @@*/ #include <errno.h> +#include <stdlib.h> #include "evsel.h" #include "machine.h"
tools/perf/util/debug.c +1 -0
@@ -7,6 +7,7 @@#include <string.h> #include <stdarg.h> #include <stdio.h> +#include <stdlib.h> #include <sys/wait.h> #include <api/debug.h> #include <linux/time64.h>
tools/perf/util/demangle-java.c +2 -1
@@ -1,14 +1,15 @@// SPDX-License-Identifier: GPL-2.0 #include <sys/types.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> -#include "util.h" #include "debug.h" #include "symbol.h" #include "demangle-java.h" #include <linux/ctype.h> +#include <linux/kernel.h> enum {MODE_PREFIX =0 ,
tools/perf/util/dwarf-aux.c +1 -1
@@ -6,7 +6,7 @@#include <errno.h> #include <inttypes.h> #include <stdbool.h> -#include "util.h" +#include <stdlib.h> #include "debug.h" #include "dwarf-aux.h" #include "string2.h"
tools/perf/util/env.c +1 -0
@@ -7,6 +7,7 @@#include <errno.h> #include <sys/utsname.h> #include <bpf/libbpf.h> +#include <stdlib.h> struct perf_env perf_env;
tools/perf/util/parse-branch-options.c +1 -1
@@ -1,9 +1,9 @@// SPDX-License-Identifier: GPL-2.0 #include "perf.h" -#include "util/util.h" #include "util/debug.h" #include <subcmd/parse-options.h> #include "util/parse-branch-options.h" +#include <stdlib.h> #define BRANCH_OPT (n, m) \ { .name = n, .mode = (m) }
tools/perf/util/parse-regs-options.c +6 -2
@@ -1,8 +1,12 @@// SPDX-License-Identifier: GPL-2.0 -#include "perf.h" -#include "util/util.h" +#include <stdbool.h> +#include <stdlib.h> +#include <stdint.h> +#include <string.h> +#include <stdio.h> #include "util/debug.h" #include <subcmd/parse-options.h> +#include "util/perf_regs.h" #include "util/parse-regs-options.h" static int
tools/perf/util/strbuf.c +1 -0
@@ -3,6 +3,7 @@#include "util.h" #include <linux/kernel.h> #include <errno.h> +#include <stdlib.h> /* * Used as the default ->buf value, so that people can always assume
tools/perf/util/symbol-elf.c +1 -0
@@ -2,6 +2,7 @@#include <fcntl.h> #include <stdio.h> #include <errno.h> +#include <stdlib.h> #include <string.h> #include <unistd.h> #include <inttypes.h>
tools/perf/util/symbol-minimal.c +1 -0
@@ -7,6 +7,7 @@#include <stdio.h> #include <fcntl.h> #include <string.h> +#include <stdlib.h> #include <byteswap.h> #include <sys/stat.h>
tools/perf/util/target.c +1 -1
@@ -10,9 +10,9 @@#include "debug.h" #include <pwd.h> +#include <stdlib.h> #include <string.h> -enum target_errno target__validate (struct target *target) {enum target_errno ret =TARGET_ERRNO__SUCCESS ;
tools/perf/util/thread-stack.c +1 -0
@@ -8,6 +8,7 @@#include <linux/list.h> #include <linux/log2.h> #include <errno.h> +#include <stdlib.h> #include "thread.h" #include "event.h" #include "machine.h"
tools/perf/util/usage.c +3 -0
@@ -9,6 +9,9 @@*/ #include "util.h" #include "debug.h" +#include <stdio.h> +#include <stdlib.h> +#include <linux/compiler.h> static __noreturn void usage_builtin (const char *err) {
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 11/25 perf namespaces: Move the conditional setns() prototype to namespaces.h
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Out of util.h, to reduce its scope, and since we have a namespaces.h header, much better to have it there, where it is related to.
--- tools/perf/util/namespaces.h | 4 ++++ tools/perf/util/setns.c | 4 +++- tools/perf/util/util.h | 4 ---- 3 files changed, 7 insertions(+), 5 deletions(-)
tools/perf/util/namespaces.h +4 -0
@@ -13,6 +13,10 @@#include <linux/refcount.h> #include <linux/types.h> +#ifndef HAVE_SETNS_SUPPORT +int setns (int fd,int nstype); +#endif +struct namespaces_event ;struct namespaces {
tools/perf/util/setns.c +3 -1
@@ -1,4 +1,6 @@ -#include "util.h" +// SPDX-License-Identifier: LGPL-2.1 + +#include "namespaces.h" #include <unistd.h> #include <sys/syscall.h>
tools/perf/util/util.h +0 -4
@@ -67,10 +67,6 @@ char *get_current_dir_name(void);int sched_getcpu (void );#endif -#ifndef HAVE_SETNS_SUPPORT -int setns (int fd,int nstype); -#endif -extern bool perf_singlethreaded;void perf_set_singlethreaded (void );
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 12/25 perf tools: Move get_current_dir_name() cond prototype out of util.h
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
And in a separate header, so that we erode util.h a bit more.
--- tools/perf/util/get_current_dir_name.c | 6 +++--- tools/perf/util/get_current_dir_name.h | 8 ++++++++ tools/perf/util/namespaces.c | 1 + tools/perf/util/util.h | 4 ---- 4 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 tools/perf/util/get_current_dir_name.h
tools/perf/util/get_current_dir_name.c +3 -3
@@ -1,8 +1,8 @@ -// SPDX-License-Identifier: GPL-2.0 -// Copyright (C) 2018, Red Hat Inc, Arnaldo Carvalho de Melo <[email protected]> +// SPDX-License-Identifier: LGPL-2.1 +// Copyright (C) 2018, 2019 Red Hat Inc, Arnaldo Carvalho de Melo <[email protected]> // #ifndef HAVE_GET_CURRENT_DIR_NAME -#include "util.h" +#include "get_current_dir_name.h" #include <unistd.h> #include <stdlib.h> #include <stdlib.h>
tools/perf/util/get_current_dir_name.h new file +8 -0
@@ -0,0 +1,8 @@ +// SPDX-License-Identifier: LGPL-2.1 +// Copyright (C) 2018, 2019 Red Hat Inc, Arnaldo Carvalho de Melo <[email protected]> +// +#ifndef __PERF_GET_CURRENT_DIR_NAME_H +#ifndef HAVE_GET_CURRENT_DIR_NAME +char *get_current_dir_name (void ); +#endif // HAVE_GET_CURRENT_DIR_NAME +#endif // __PERF_GET_CURRENT_DIR_NAME_H
tools/perf/util/namespaces.c +1 -0
@@ -7,6 +7,7 @@#include "namespaces.h" #include "util.h" #include "event.h" +#include "get_current_dir_name.h" #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h>
tools/perf/util/util.h +0 -4
@@ -59,10 +59,6 @@ int fetch_kernel_version(unsigned int *puint,const char *perf_tip (const char *dirpath); -#ifndef HAVE_GET_CURRENT_DIR_NAME -char *get_current_dir_name (void ); -#endif -#ifndef HAVE_SCHED_GETCPU_SUPPORT int sched_getcpu (void );#endif
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 13/25 tools lib: Adopt zalloc()/zfree() from tools/perf
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Eroding a bit more the tools/perf/util/util.h hodpodge header.
--- tools/include/linux/zalloc.h | 12 ++++++++++++ tools/lib/zalloc.c | 15 +++++++++++++++ tools/perf/MANIFEST | 1 + tools/perf/arch/arm/annotate/instructions.c | 1 + tools/perf/arch/arm/util/auxtrace.c | 1 + tools/perf/arch/arm/util/cs-etm.c | 1 + tools/perf/arch/arm64/util/arm-spe.c | 1 + tools/perf/arch/common.c | 2 +- tools/perf/arch/powerpc/util/perf_regs.c | 2 +- tools/perf/arch/s390/util/auxtrace.c | 1 + tools/perf/arch/s390/util/header.c | 2 +- tools/perf/arch/x86/util/event.c | 2 +- tools/perf/arch/x86/util/intel-bts.c | 2 +- tools/perf/arch/x86/util/intel-pt.c | 2 +- tools/perf/arch/x86/util/perf_regs.c | 2 +- tools/perf/bench/mem-functions.c | 2 +- tools/perf/bench/numa.c | 2 +- tools/perf/builtin-annotate.c | 2 +- tools/perf/builtin-bench.c | 2 +- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-diff.c | 2 +- tools/perf/builtin-help.c | 1 + tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-kvm.c | 2 +- tools/perf/builtin-lock.c | 2 +- tools/perf/builtin-probe.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-sched.c | 2 +- tools/perf/builtin-script.c | 2 +- tools/perf/builtin-stat.c | 2 +- tools/perf/builtin-timechart.c | 4 +--- tools/perf/builtin-trace.c | 1 + tools/perf/perf.c | 2 +- tools/perf/tests/switch-tracking.c | 1 + tools/perf/ui/browser.c | 2 +- tools/perf/ui/browsers/annotate.c | 2 +- tools/perf/ui/browsers/hists.c | 2 +- tools/perf/ui/gtk/util.c | 3 +-- tools/perf/ui/stdio/hist.c | 2 +- tools/perf/util/Build | 5 +++++ tools/perf/util/arm-spe.c | 2 +- tools/perf/util/auxtrace.c | 2 +- tools/perf/util/bpf-loader.c | 1 + tools/perf/util/build-id.c | 1 + tools/perf/util/call-path.c | 3 ++- tools/perf/util/callchain.c | 2 +- tools/perf/util/cgroup.c | 2 +- tools/perf/util/comm.c | 2 +- tools/perf/util/config.c | 3 +-- tools/perf/util/counts.c | 2 +- tools/perf/util/cpumap.c | 2 +- tools/perf/util/cputopo.c | 2 +- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 1 + tools/perf/util/cs-etm.c | 1 + tools/perf/util/data-convert-bt.c | 2 +- tools/perf/util/data.c | 1 + tools/perf/util/db-export.c | 2 +- tools/perf/util/dso.c | 3 ++- tools/perf/util/env.c | 2 +- tools/perf/util/event.c | 1 + tools/perf/util/evlist.c | 2 +- tools/perf/util/evsel.c | 2 +- tools/perf/util/header.c | 2 +- tools/perf/util/help-unknown-cmd.c | 2 ++ tools/perf/util/hist.c | 2 +- tools/perf/util/intel-bts.c | 2 +- .../perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 +- tools/perf/util/intel-pt.c | 2 +- tools/perf/util/llvm-utils.c | 1 + tools/perf/util/machine.c | 2 +- tools/perf/util/map.c | 2 +- tools/perf/util/mem2node.c | 2 +- tools/perf/util/mmap.c | 1 + tools/perf/util/namespaces.c | 2 +- tools/perf/util/parse-events.c | 1 + tools/perf/util/pmu.c | 2 +- tools/perf/util/probe-event.c | 2 +- tools/perf/util/probe-file.c | 2 +- tools/perf/util/probe-finder.c | 2 +- tools/perf/util/pstack.c | 2 +- tools/perf/util/python-ext-sources | 1 + tools/perf/util/s390-cpumsf.c | 2 +- tools/perf/util/session.c | 2 +- tools/perf/util/srcline.c | 2 +- tools/perf/util/stat.c | 1 + tools/perf/util/strbuf.c | 2 +- tools/perf/util/strfilter.c | 3 ++- tools/perf/util/strlist.c | 2 +- tools/perf/util/svghelper.c | 2 +- tools/perf/util/symbol-elf.c | 1 + tools/perf/util/symbol-minimal.c | 2 +- tools/perf/util/symbol.c | 1 + tools/perf/util/syscalltbl.c | 2 +- tools/perf/util/thread-stack.c | 2 +- tools/perf/util/thread.c | 2 +- tools/perf/util/thread_map.c | 2 +- tools/perf/util/trace-event-info.c | 1 + tools/perf/util/trace-event-scripting.c | 2 +- tools/perf/util/unwind-libdw.c | 1 + tools/perf/util/util.h | 9 --------- tools/perf/util/values.c | 2 +- tools/perf/util/vdso.c | 1 + tools/perf/util/xyarray.c | 2 +- 103 files changed, 135 insertions(+), 86 deletions(-) create mode 100644 tools/include/linux/zalloc.h create mode 100644 tools/lib/zalloc.c
tools/include/linux/zalloc.h new file +12 -0
@@ -0,0 +1,12 @@ +// SPDX-License-Identifier: LGPL-2.1 +#ifndef __TOOLS_LINUX_ZALLOC_H +#define __TOOLS_LINUX_ZALLOC_H + +#include <stddef.h> + +void *zalloc (size_t size); +void __zfree (void **ptr); + +#define zfree (ptr) __zfree((void **)(ptr)) + +#endif // __TOOLS_LINUX_ZALLOC_H
tools/lib/zalloc.c new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: LGPL-2.1 + +#include <stdlib.h> +#include <linux/zalloc.h> + +void *zalloc (size_t size) +{ +return calloc (1 , size); +} + +void __zfree (void **ptr) +{ +free (*ptr); + *ptr =NULL ; +}
tools/perf/MANIFEST +1 -0
@@ -18,3 +18,4 @@ tools/lib/find_bit.c tools/lib/bitmap.c tools/lib/str_error_r.c tools/lib/vsprintf.c +tools/lib/zalloc.c
tools/perf/arch/arm/annotate/instructions.c +1 -0
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/compiler.h> +#include <linux/zalloc.h> #include <sys/types.h> #include <regex.h>
tools/perf/arch/arm/util/auxtrace.c +1 -0
@@ -6,6 +6,7 @@#include <stdbool.h> #include <linux/coresight-pmu.h> +#include <linux/zalloc.h> #include "../../util/auxtrace.h" #include "../../util/evlist.h"
tools/perf/arch/arm/util/cs-etm.c +1 -0
@@ -12,6 +12,7 @@#include <linux/kernel.h> #include <linux/log2.h> #include <linux/types.h> +#include <linux/zalloc.h> #include "cs-etm.h" #include "../../perf.h"
tools/perf/arch/arm64/util/arm-spe.c +1 -0
@@ -8,6 +8,7 @@#include <linux/types.h> #include <linux/bitops.h> #include <linux/log2.h> +#include <linux/zalloc.h> #include <time.h> #include "../../util/cpumap.h"
tools/perf/arch/common.c +1 -1
@@ -3,8 +3,8 @@#include <stdlib.h> #include "common.h" #include "../util/env.h" -#include "../util/util.h" #include "../util/debug.h" +#include <linux/zalloc.h> const char *const arc_triplets[] = {"arc-linux-" ,
tools/perf/arch/powerpc/util/perf_regs.c +1 -1
@@ -2,9 +2,9 @@#include <errno.h> #include <string.h> #include <regex.h> +#include <linux/zalloc.h> #include "../../perf.h" -#include "../../util/util.h" #include "../../util/perf_regs.h" #include "../../util/debug.h"
tools/perf/arch/s390/util/auxtrace.c +1 -0
@@ -3,6 +3,7 @@#include <linux/types.h> #include <linux/bitops.h> #include <linux/log2.h> +#include <linux/zalloc.h> #include "../../util/evlist.h" #include "../../util/auxtrace.h"
tools/perf/arch/s390/util/header.c +1 -1
@@ -13,9 +13,9 @@#include <string.h> #include <linux/ctype.h> #include <linux/kernel.h> +#include <linux/zalloc.h> #include "../../util/header.h" -#include "../../util/util.h" #define SYSINFO_MANU "Manufacturer:"#define SYSINFO_TYPE "Type:"
tools/perf/arch/x86/util/event.c +1 -1
@@ -1,11 +1,11 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/types.h> #include <linux/string.h> +#include <linux/zalloc.h> #include "../../util/machine.h" #include "../../util/tool.h" #include "../../util/map.h" -#include "../../util/util.h" #include "../../util/debug.h" #if defined(__x86_64__)
tools/perf/arch/x86/util/intel-bts.c +1 -1
@@ -9,12 +9,12 @@#include <linux/types.h> #include <linux/bitops.h> #include <linux/log2.h> +#include <linux/zalloc.h> #include "../../util/cpumap.h" #include "../../util/evsel.h" #include "../../util/evlist.h" #include "../../util/session.h" -#include "../../util/util.h" #include "../../util/pmu.h" #include "../../util/debug.h" #include "../../util/tsc.h"
tools/perf/arch/x86/util/intel-pt.c +1 -1
@@ -10,6 +10,7 @@#include <linux/types.h> #include <linux/bitops.h> #include <linux/log2.h> +#include <linux/zalloc.h> #include <cpuid.h> #include "../../perf.h"
@@ -25,7 +26,6 @@#include "../../util/auxtrace.h" #include "../../util/tsc.h" #include "../../util/intel-pt.h" -#include "../../util/util.h" #define KiB (x) ((x) * 1024)#define MiB (x) ((x) * 1024 * 1024)
tools/perf/arch/x86/util/perf_regs.c +1 -1
@@ -2,9 +2,9 @@#include <errno.h> #include <string.h> #include <regex.h> +#include <linux/zalloc.h> #include "../../perf.h" -#include "../../util/util.h" #include "../../util/perf_regs.h" #include "../../util/debug.h"
tools/perf/bench/mem-functions.c +1 -1
@@ -9,7 +9,6 @@#include "debug.h" #include "../perf.h" -#include "../util/util.h" #include <subcmd/parse-options.h> #include "../util/header.h" #include "../util/cloexec.h"
@@ -24,6 +23,7 @@#include <sys/time.h> #include <errno.h> #include <linux/time64.h> +#include <linux/zalloc.h> #define K 1024
tools/perf/bench/numa.c +1 -1
@@ -11,7 +11,6 @@#include "../perf.h" #include "../builtin.h" -#include "../util/util.h" #include <subcmd/parse-options.h> #include "../util/cloexec.h"
@@ -35,6 +34,7 @@#include <linux/kernel.h> #include <linux/time64.h> #include <linux/numa.h> +#include <linux/zalloc.h> #include <numa.h> #include <numaif.h>
tools/perf/builtin-annotate.c +1 -1
@@ -8,11 +8,11 @@*/ #include "builtin.h" -#include "util/util.h" #include "util/color.h" #include <linux/list.h> #include "util/cache.h" #include <linux/rbtree.h> +#include <linux/zalloc.h> #include "util/symbol.h" #include "perf.h"
tools/perf/builtin-bench.c +1 -1
@@ -17,7 +17,6 @@* epoll ... Event poll performance */ #include "perf.h" -#include "util/util.h" #include <subcmd/parse-options.h> #include "builtin.h" #include "bench/bench.h"
@@ -26,6 +25,7 @@#include <stdlib.h> #include <string.h> #include <sys/prctl.h> +#include <linux/zalloc.h> typedef int (*bench_fn_t )(int argc,const char **argv);
tools/perf/builtin-c2c.c +1 -1
@@ -15,9 +15,9 @@#include <linux/compiler.h> #include <linux/kernel.h> #include <linux/stringify.h> +#include <linux/zalloc.h> #include <asm/bug.h> #include <sys/param.h> -#include "util.h" #include "debug.h" #include "builtin.h" #include <subcmd/parse-options.h>
tools/perf/builtin-diff.c +1 -1
@@ -16,12 +16,12 @@#include "util/tool.h" #include "util/sort.h" #include "util/symbol.h" -#include "util/util.h" #include "util/data.h" #include "util/config.h" #include "util/time-utils.h" #include "util/annotate.h" #include "util/map.h" +#include <linux/zalloc.h> #include <errno.h> #include <inttypes.h>
tools/perf/builtin-help.c +1 -0
@@ -14,6 +14,7 @@#include <subcmd/help.h> #include "util/debug.h" #include <linux/kernel.h> +#include <linux/zalloc.h> #include <errno.h> #include <stdio.h> #include <stdlib.h>
tools/perf/builtin-kmem.c +1 -1
@@ -4,7 +4,6 @@#include "util/evlist.h" #include "util/evsel.h" -#include "util/util.h" #include "util/config.h" #include "util/map.h" #include "util/symbol.h"
@@ -26,6 +25,7 @@#include <linux/kernel.h> #include <linux/rbtree.h> #include <linux/string.h> +#include <linux/zalloc.h> #include <errno.h> #include <inttypes.h> #include <locale.h>
tools/perf/builtin-kvm.c +1 -1
@@ -5,7 +5,6 @@#include "util/evsel.h" #include "util/evlist.h" #include "util/term.h" -#include "util/util.h" #include "util/cache.h" #include "util/symbol.h" #include "util/thread.h"
@@ -32,6 +31,7 @@#include <linux/kernel.h> #include <linux/time64.h> +#include <linux/zalloc.h> #include <errno.h> #include <inttypes.h> #include <poll.h>
tools/perf/builtin-lock.c +1 -1
@@ -6,7 +6,6 @@#include "util/evlist.h" #include "util/evsel.h" -#include "util/util.h" #include "util/cache.h" #include "util/symbol.h" #include "util/thread.h"
@@ -30,6 +29,7 @@#include <linux/list.h> #include <linux/hash.h> #include <linux/kernel.h> +#include <linux/zalloc.h> static struct perf_session *session;
tools/perf/builtin-probe.c +1 -1
@@ -19,7 +19,6 @@#include "perf.h" #include "builtin.h" #include "namespaces.h" -#include "util/util.h" #include "util/strlist.h" #include "util/strfilter.h" #include "util/symbol.h"
@@ -28,6 +27,7 @@#include "util/probe-finder.h" #include "util/probe-event.h" #include "util/probe-file.h" +#include <linux/zalloc.h> #define DEFAULT_VAR_FILTER "!__k???tab_* & !__crc_*"#define DEFAULT_FUNC_FILTER "!_*"
tools/perf/builtin-report.c +1 -1
@@ -8,7 +8,6 @@*/ #include "builtin.h" -#include "util/util.h" #include "util/config.h" #include "util/annotate.h"
@@ -16,6 +15,7 @@#include <linux/list.h> #include <linux/rbtree.h> #include <linux/err.h> +#include <linux/zalloc.h> #include "util/map.h" #include "util/symbol.h" #include "util/callchain.h"
tools/perf/builtin-sched.c +1 -1
@@ -2,7 +2,6 @@#include "builtin.h" #include "perf.h" -#include "util/util.h" #include "util/evlist.h" #include "util/cache.h" #include "util/evsel.h"
@@ -26,6 +25,7 @@#include <linux/kernel.h> #include <linux/log2.h> +#include <linux/zalloc.h> #include <sys/prctl.h> #include <sys/resource.h> #include <inttypes.h>
tools/perf/builtin-script.c +1 -1
@@ -14,7 +14,6 @@#include "util/symbol.h" #include "util/thread.h" #include "util/trace-event.h" -#include "util/util.h" #include "util/evlist.h" #include "util/evsel.h" #include "util/sort.h"
@@ -34,6 +33,7 @@#include <linux/kernel.h> #include <linux/stringify.h> #include <linux/time64.h> +#include <linux/zalloc.h> #include <sys/utsname.h> #include "asm/bug.h" #include "util/mem-events.h"
tools/perf/builtin-stat.c +1 -1
@@ -43,7 +43,6 @@#include "perf.h" #include "builtin.h" #include "util/cgroup.h" -#include "util/util.h" #include <subcmd/parse-options.h> #include "util/parse-events.h" #include "util/pmu.h"
@@ -67,6 +66,7 @@#include "asm/bug.h" #include <linux/time64.h> +#include <linux/zalloc.h> #include <api/fs/fs.h> #include <errno.h> #include <signal.h>
tools/perf/builtin-timechart.c +1 -3
@@ -13,9 +13,6 @@#include <traceevent/event-parse.h> #include "builtin.h" - -#include "util/util.h" -#include "util/color.h" #include <linux/list.h> #include "util/cache.h"
@@ -24,6 +21,7 @@#include <linux/kernel.h> #include <linux/rbtree.h> #include <linux/time64.h> +#include <linux/zalloc.h> #include "util/symbol.h" #include "util/thread.h" #include "util/callchain.h"
tools/perf/builtin-trace.c +1 -0
@@ -61,6 +61,7 @@#include <linux/random.h> #include <linux/stringify.h> #include <linux/time64.h> +#include <linux/zalloc.h> #include <fcntl.h> #include <sys/sysmacros.h>
tools/perf/perf.c +1 -1
@@ -18,7 +18,6 @@#include "util/bpf-loader.h" #include "util/debug.h" #include "util/event.h" -#include "util/util.h" #include <api/fs/fs.h> #include <api/fs/tracing_path.h> #include <errno.h>
@@ -30,6 +29,7 @@#include <sys/stat.h> #include <unistd.h> #include <linux/kernel.h> +#include <linux/zalloc.h> const char perf_usage_string[] ="perf [--version] [--help] [OPTIONS] COMMAND [ARGS]" ;
tools/perf/tests/switch-tracking.c +1 -0
@@ -4,6 +4,7 @@#include <errno.h> #include <time.h> #include <stdlib.h> +#include <linux/zalloc.h> #include "parse-events.h" #include "evlist.h"
tools/perf/ui/browser.c +1 -1
@@ -1,5 +1,4 @@// SPDX-License-Identifier: GPL-2.0 -#include "../util.h" #include "../string2.h" #include "../config.h" #include "../../perf.h"
@@ -17,6 +16,7 @@#include "keysyms.h" #include "../color.h" #include <linux/ctype.h> +#include <linux/zalloc.h> static int ui_browser__percent_color (struct ui_browser *browser,double percent,bool current)
tools/perf/ui/browsers/annotate.c +1 -1
@@ -1,5 +1,4 @@// SPDX-License-Identifier: GPL-2.0 -#include "../../util/util.h" #include "../browser.h" #include "../helpline.h" #include "../ui.h"
@@ -15,6 +14,7 @@#include <pthread.h> #include <linux/kernel.h> #include <linux/string.h> +#include <linux/zalloc.h> #include <sys/ttydefaults.h> #include <asm/bug.h>
tools/perf/ui/browsers/hists.c +1 -1
@@ -9,6 +9,7 @@#include <linux/string.h> #include <sys/ttydefaults.h> #include <linux/time64.h> +#include <linux/zalloc.h> #include "../../util/callchain.h" #include "../../util/evsel.h"
@@ -18,7 +19,6 @@#include "../../util/symbol.h" #include "../../util/pstack.h" #include "../../util/sort.h" -#include "../../util/util.h" #include "../../util/top.h" #include "../../util/thread.h" #include "../../arch/common.h"
tools/perf/ui/gtk/util.c +1 -2
@@ -1,11 +1,10 @@// SPDX-License-Identifier: GPL-2.0 #include "../util.h" -#include "../../util/util.h" #include "../../util/debug.h" #include "gtk.h" #include <string.h> - +#include <linux/zalloc.h> struct perf_gtk_context *pgctx;
tools/perf/ui/stdio/hist.c +1 -1
@@ -3,7 +3,6 @@#include <linux/string.h> #include "../../util/callchain.h" -#include "../../util/util.h" #include "../../util/hist.h" #include "../../util/map.h" #include "../../util/map_groups.h"
@@ -14,6 +13,7 @@#include "../../util/string2.h" #include "../../util/thread.h" #include <linux/ctype.h> +#include <linux/zalloc.h> static size_t callchain__fprintf_left_margin (FILE *fp,int left_margin) {
tools/perf/util/Build +5 -0
@@ -25,6 +25,7 @@ perf-y += rbtree.o perf-y += libstring.o perf-y += bitmap.o perf-y += hweight.o +perf-y += zalloc.o perf-y += smt.o perf-y += strbuf.o perf-y += string.o
@@ -241,3 +242,7 @@ $(OUTPUT)util/hweight.o: ../lib/hweight.c FORCE $(OUTPUT)util/vsprintf.o: ../lib/vsprintf.c FORCE $(call rule_mkdir) $(call if_changed_dep,cc_o_c) + +$(OUTPUT)util/zalloc.o: ../lib/zalloc.c FORCE + $(call rule_mkdir) + $(call if_changed_dep,cc_o_c)
tools/perf/util/arm-spe.c +1 -1
@@ -12,6 +12,7 @@#include <linux/types.h> #include <linux/bitops.h> #include <linux/log2.h> +#include <linux/zalloc.h> #include "cpumap.h" #include "color.h"
@@ -19,7 +20,6 @@#include "evlist.h" #include "machine.h" #include "session.h" -#include "util.h" #include "thread.h" #include "debug.h" #include "auxtrace.h"
tools/perf/util/auxtrace.c +1 -1
@@ -24,9 +24,9 @@#include <stdlib.h> #include <stdio.h> #include <linux/list.h> +#include <linux/zalloc.h> #include "../perf.h" -#include "util.h" #include "evlist.h" #include "dso.h" #include "map.h"
tools/perf/util/bpf-loader.c +1 -0
@@ -12,6 +12,7 @@#include <linux/err.h> #include <linux/kernel.h> #include <linux/string.h> +#include <linux/zalloc.h> #include <errno.h> #include "perf.h" #include "debug.h"
tools/perf/util/build-id.c +1 -0
@@ -30,6 +30,7 @@#include "strlist.h" #include <linux/ctype.h> +#include <linux/zalloc.h> static bool no_buildid_cache;
tools/perf/util/call-path.c +2 -1
@@ -6,8 +6,9 @@#include <linux/rbtree.h> #include <linux/list.h> +#include <linux/zalloc.h> +#include <stdlib.h> -#include "util.h" #include "call-path.h" static void call_path__init(struct call_path *cp, struct call_path *parent,
tools/perf/util/callchain.c +1 -1
@@ -16,11 +16,11 @@#include <stdbool.h> #include <errno.h> #include <math.h> +#include <linux/zalloc.h> #include "asm/bug.h" #include "hist.h" -#include "util.h" #include "sort.h" #include "machine.h" #include "map.h"
tools/perf/util/cgroup.c +1 -1
@@ -1,11 +1,11 @@// SPDX-License-Identifier: GPL-2.0 -#include "util.h" #include "../perf.h" #include <subcmd/parse-options.h> #include "evsel.h" #include "cgroup.h" #include "evlist.h" #include <linux/stringify.h> +#include <linux/zalloc.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h>
tools/perf/util/comm.c +1 -1
@@ -1,12 +1,12 @@// SPDX-License-Identifier: GPL-2.0 #include "comm.h" -#include "util.h" #include <errno.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <linux/refcount.h> #include <linux/rbtree.h> +#include <linux/zalloc.h> #include "rwsem.h" struct comm_str {
tools/perf/util/config.c +1 -2
@@ -11,7 +11,6 @@*/ #include <errno.h> #include <sys/param.h> -#include "util.h" #include "cache.h" #include "callchain.h" #include <subcmd/exec-cmd.h>
@@ -23,7 +22,7 @@#include <sys/stat.h> #include <unistd.h> #include <linux/string.h> - +#include <linux/zalloc.h> #include <linux/ctype.h> #define MAXNAME (256)
tools/perf/util/counts.c +1 -1
@@ -3,7 +3,7 @@#include <stdlib.h> #include "evsel.h" #include "counts.h" -#include "util.h" +#include <linux/zalloc.h> struct perf_counts *perf_counts__new (int ncpus,int nthreads) {
tools/perf/util/cpumap.c +1 -1
@@ -1,5 +1,4 @@// SPDX-License-Identifier: GPL-2.0 -#include "util.h" #include <api/fs/fs.h> #include "../perf.h" #include "cpumap.h"
@@ -11,6 +10,7 @@#include "asm/bug.h" #include <linux/ctype.h> +#include <linux/zalloc.h> static int max_cpu_num;static int max_present_cpu_num;
tools/perf/util/cputopo.c +1 -1
@@ -4,10 +4,10 @@#include <inttypes.h> #include <stdlib.h> #include <api/fs/fs.h> +#include <linux/zalloc.h> #include "cputopo.h" #include "cpumap.h" -#include "util.h" #include "env.h" #define CORE_SIB_FMT \
tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +1 -0
@@ -8,6 +8,7 @@#include <linux/err.h> #include <linux/list.h> +#include <linux/zalloc.h> #include <stdlib.h> #include <opencsd/c_api/opencsd_c_api.h> #include <opencsd/etmv4/trc_pkt_types_etmv4.h>
tools/perf/util/cs-etm.c +1 -0
@@ -11,6 +11,7 @@#include <linux/kernel.h> #include <linux/log2.h> #include <linux/types.h> +#include <linux/zalloc.h> #include <opencsd/ocsd_if_types.h> #include <stdlib.h>
tools/perf/util/data-convert-bt.c +1 -1
@@ -10,6 +10,7 @@#include <inttypes.h> #include <linux/compiler.h> #include <linux/kernel.h> +#include <linux/zalloc.h> #include <babeltrace/ctf-writer/writer.h> #include <babeltrace/ctf-writer/clock.h> #include <babeltrace/ctf-writer/stream.h>
@@ -22,7 +23,6 @@#include "asm/bug.h" #include "data-convert-bt.h" #include "session.h" -#include "util.h" #include "debug.h" #include "tool.h" #include "evlist.h"
tools/perf/util/data.c +1 -0
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/compiler.h> #include <linux/kernel.h> +#include <linux/zalloc.h> #include <sys/types.h> #include <sys/stat.h> #include <errno.h>
tools/perf/util/db-export.c +1 -1
@@ -14,11 +14,11 @@#include "symbol.h" #include "map.h" #include "event.h" -#include "util.h" #include "thread-stack.h" #include "callchain.h" #include "call-path.h" #include "db-export.h" +#include <linux/zalloc.h> struct deferred_export {struct list_head node;
tools/perf/util/dso.c +2 -1
@@ -2,6 +2,7 @@#include <asm/bug.h> #include <linux/kernel.h> #include <linux/string.h> +#include <linux/zalloc.h> #include <sys/time.h> #include <sys/resource.h> #include <sys/types.h>
@@ -21,7 +22,7 @@#include "dso.h" #include "machine.h" #include "auxtrace.h" -#include "util.h" +#include "util.h" /* O_CLOEXEC for older systems */ #include "debug.h" #include "string2.h" #include "vdso.h"
tools/perf/util/env.c +1 -1
@@ -2,7 +2,7 @@#include "cpumap.h" #include "env.h" #include <linux/ctype.h> -#include "util.h" +#include <linux/zalloc.h> #include "bpf-event.h" #include <errno.h> #include <sys/utsname.h>
tools/perf/util/event.c +1 -0
@@ -11,6 +11,7 @@#include <uapi/linux/mman.h> /* To get things like MAP_HUGETLB even on older libc headers */ #include <api/fs/fs.h> #include <linux/perf_event.h> +#include <linux/zalloc.h> #include "event.h" #include "debug.h" #include "hist.h"
tools/perf/util/evlist.c +1 -1
@@ -5,7 +5,6 @@* Parts came from builtin-{top,stat,record}.c, see those files for further * copyright notes. */ -#include "util.h" #include <api/fs/fs.h> #include <errno.h> #include <inttypes.h>
@@ -33,6 +32,7 @@#include <linux/hash.h> #include <linux/log2.h> #include <linux/err.h> +#include <linux/zalloc.h> #ifdef LACKS_SIGQUEUE_PROTOTYPE int sigqueue (pid_t pid,int sig,const union sigval value);
tools/perf/util/evsel.c +1 -1
@@ -17,6 +17,7 @@#include <linux/perf_event.h> #include <linux/compiler.h> #include <linux/err.h> +#include <linux/zalloc.h> #include <sys/ioctl.h> #include <sys/resource.h> #include <sys/types.h>
@@ -27,7 +28,6 @@#include "event.h" #include "evsel.h" #include "evlist.h" -#include "util.h" #include "cpumap.h" #include "thread_map.h" #include "target.h"
tools/perf/util/header.c +1 -1
@@ -1,7 +1,6 @@// SPDX-License-Identifier: GPL-2.0 #include <errno.h> #include <inttypes.h> -#include "util.h" #include "string2.h" #include <sys/param.h> #include <sys/types.h>
@@ -15,6 +14,7 @@#include <linux/bitops.h> #include <linux/string.h> #include <linux/stringify.h> +#include <linux/zalloc.h> #include <sys/stat.h> #include <sys/utsname.h> #include <linux/time64.h>
tools/perf/util/help-unknown-cmd.c +2 -0
@@ -3,9 +3,11 @@#include "config.h" #include <poll.h> #include <stdio.h> +#include <stdlib.h> #include <subcmd/help.h> #include "../builtin.h" #include "levenshtein.h" +#include <linux/zalloc.h> static int autocorrect;
tools/perf/util/hist.c +1 -1
@@ -1,6 +1,5 @@// SPDX-License-Identifier: GPL-2.0 #include "callchain.h" -#include "util.h" #include "build-id.h" #include "hist.h" #include "map.h"
@@ -20,6 +19,7 @@#include <inttypes.h> #include <sys/param.h> #include <linux/time64.h> +#include <linux/zalloc.h> static bool hists__filter_entry_by_dso (struct hists *hists,struct hist_entry *he);
tools/perf/util/intel-bts.c +1 -1
@@ -12,6 +12,7 @@#include <linux/types.h> #include <linux/bitops.h> #include <linux/log2.h> +#include <linux/zalloc.h> #include "cpumap.h" #include "color.h"
@@ -21,7 +22,6 @@#include "map.h" #include "symbol.h" #include "session.h" -#include "util.h" #include "thread.h" #include "thread-stack.h" #include "debug.h"
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +1 -1
@@ -14,9 +14,9 @@#include <stdint.h> #include <inttypes.h> #include <linux/compiler.h> +#include <linux/zalloc.h> #include "../cache.h" -#include "../util.h" #include "../auxtrace.h" #include "intel-pt-insn-decoder.h"
tools/perf/util/intel-pt.c +1 -1
@@ -10,6 +10,7 @@#include <errno.h> #include <linux/kernel.h> #include <linux/types.h> +#include <linux/zalloc.h> #include "../perf.h" #include "session.h"
@@ -22,7 +23,6 @@#include "evsel.h" #include "map.h" #include "color.h" -#include "util.h" #include "thread.h" #include "thread-stack.h" #include "symbol.h"
tools/perf/util/llvm-utils.c +1 -0
@@ -9,6 +9,7 @@#include <stdio.h> #include <stdlib.h> #include <linux/err.h> +#include <linux/zalloc.h> #include "debug.h" #include "llvm-utils.h" #include "config.h"
tools/perf/util/machine.c +1 -1
@@ -15,7 +15,6 @@#include "strlist.h" #include "thread.h" #include "vdso.h" -#include "util.h" #include <stdbool.h> #include <sys/types.h> #include <sys/stat.h>
@@ -28,6 +27,7 @@#include <linux/ctype.h> #include <symbol/kallsyms.h> #include <linux/mman.h> +#include <linux/zalloc.h> static void __machine__remove_thread (struct machine *machine,struct thread *th,bool lock);
tools/perf/util/map.c +1 -1
@@ -12,10 +12,10 @@#include "thread.h" #include "vdso.h" #include "build-id.h" -#include "util.h" #include "debug.h" #include "machine.h" #include <linux/string.h> +#include <linux/zalloc.h> #include "srcline.h" #include "namespaces.h" #include "unwind.h"
tools/perf/util/mem2node.c +1 -1
@@ -1,8 +1,8 @@#include <errno.h> #include <inttypes.h> #include <linux/bitmap.h> +#include <linux/zalloc.h> #include "mem2node.h" -#include "util.h" struct phys_entry {struct rb_node rb_node;
tools/perf/util/mmap.c +1 -0
@@ -9,6 +9,7 @@#include <sys/mman.h> #include <inttypes.h> #include <asm/bug.h> +#include <linux/zalloc.h> #ifdef HAVE_LIBNUMA_SUPPORT #include <numaif.h> #endif
tools/perf/util/namespaces.c +1 -1
@@ -5,7 +5,6 @@*/ #include "namespaces.h" -#include "util.h" #include "event.h" #include "get_current_dir_name.h" #include <sys/types.h>
@@ -18,6 +17,7 @@#include <string.h> #include <unistd.h> #include <asm/bug.h> +#include <linux/zalloc.h> struct namespaces *namespaces__new (struct namespaces_event *event) {
tools/perf/util/parse-events.c +1 -0
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/hw_breakpoint.h> #include <linux/err.h> +#include <linux/zalloc.h> #include <dirent.h> #include <errno.h> #include <sys/ioctl.h>
tools/perf/util/pmu.c +1 -1
@@ -2,6 +2,7 @@#include <linux/list.h> #include <linux/compiler.h> #include <linux/string.h> +#include <linux/zalloc.h> #include <sys/types.h> #include <errno.h> #include <fcntl.h>
@@ -14,7 +15,6 @@#include <api/fs/fs.h> #include <locale.h> #include <regex.h> -#include "util.h" #include "pmu.h" #include "parse-events.h" #include "cpumap.h"
tools/perf/util/probe-event.c +1 -1
@@ -19,7 +19,6 @@#include <limits.h> #include <elf.h> -#include "util.h" #include "event.h" #include "namespaces.h" #include "strlist.h"
@@ -40,6 +39,7 @@#include "string2.h" #include <linux/ctype.h> +#include <linux/zalloc.h> #define PERFPROBE_GROUP "probe"
tools/perf/util/probe-file.c +1 -1
@@ -10,8 +10,8 @@#include <sys/types.h> #include <sys/uio.h> #include <unistd.h> +#include <linux/zalloc.h> #include "namespaces.h" -#include "util.h" #include "event.h" #include "strlist.h" #include "strfilter.h"
tools/perf/util/probe-finder.c +1 -1
@@ -19,11 +19,11 @@#include <dwarf-regs.h> #include <linux/bitops.h> +#include <linux/zalloc.h> #include "event.h" #include "dso.h" #include "debug.h" #include "intlist.h" -#include "util.h" #include "strlist.h" #include "symbol.h" #include "probe-finder.h"
tools/perf/util/pstack.c +1 -1
@@ -5,10 +5,10 @@* (c) 2010 Arnaldo Carvalho de Melo <[email protected]> */ -#include "util.h" #include "pstack.h" #include "debug.h" #include <linux/kernel.h> +#include <linux/zalloc.h> #include <stdlib.h> struct pstack {
tools/perf/util/python-ext-sources +1 -0
@@ -18,6 +18,7 @@ util/namespaces.c ../lib/hweight.c ../lib/string.c ../lib/vsprintf.c +../lib/zalloc.c util/thread_map.c util/util.c util/xyarray.c
tools/perf/util/s390-cpumsf.c +1 -1
@@ -146,6 +146,7 @@#include <linux/types.h> #include <linux/bitops.h> #include <linux/log2.h> +#include <linux/zalloc.h> #include <sys/stat.h> #include <sys/types.h>
@@ -156,7 +157,6 @@#include "evlist.h" #include "machine.h" #include "session.h" -#include "util.h" #include "thread.h" #include "debug.h" #include "auxtrace.h"
tools/perf/util/session.c +1 -1
@@ -2,6 +2,7 @@#include <errno.h> #include <inttypes.h> #include <linux/kernel.h> +#include <linux/zalloc.h> #include <traceevent/event-parse.h> #include <api/fs/fs.h>
@@ -18,7 +19,6 @@#include "session.h" #include "tool.h" #include "sort.h" -#include "util.h" #include "cpumap.h" #include "perf_regs.h" #include "asm/bug.h"
tools/perf/util/srcline.c +1 -1
@@ -6,9 +6,9 @@#include <linux/kernel.h> #include <linux/string.h> +#include <linux/zalloc.h> #include "util/dso.h" -#include "util/util.h" #include "util/debug.h" #include "util/callchain.h" #include "util/symbol_conf.h"
tools/perf/util/stat.c +1 -0
@@ -6,6 +6,7 @@#include "evlist.h" #include "evsel.h" #include "thread_map.h" +#include <linux/zalloc.h> void update_stats (struct stats *stats,u64 val) {
tools/perf/util/strbuf.c +1 -1
@@ -1,7 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include "debug.h" -#include "util.h" #include <linux/kernel.h> +#include <linux/zalloc.h> #include <errno.h> #include <stdlib.h>
tools/perf/util/strfilter.c +2 -1
@@ -1,11 +1,12 @@// SPDX-License-Identifier: GPL-2.0 -#include "util.h" #include "string2.h" #include "strfilter.h" #include <errno.h> +#include <stdlib.h> #include <linux/ctype.h> #include <linux/string.h> +#include <linux/zalloc.h> /* Operators */ static const char *OP_and ="&" ;/* Logical AND */
tools/perf/util/strlist.c +1 -1
@@ -4,12 +4,12 @@*/ #include "strlist.h" -#include "util.h" #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <linux/zalloc.h> static struct rb_node *strlist__node_new (struct rblist *rblist,const void *entry)
tools/perf/util/svghelper.c +1 -1
@@ -15,10 +15,10 @@#include <string.h> #include <linux/bitmap.h> #include <linux/time64.h> +#include <linux/zalloc.h> #include "perf.h" #include "svghelper.h" -#include "util.h" #include "cpumap.h" static u64 first_time, last_time;
tools/perf/util/symbol-elf.c +1 -0
@@ -17,6 +17,7 @@#include "debug.h" #include "util.h" #include <linux/ctype.h> +#include <linux/zalloc.h> #include <symbol/kallsyms.h> #ifndef EM_AARCH64
tools/perf/util/symbol-minimal.c +1 -1
@@ -10,7 +10,7 @@#include <stdlib.h> #include <byteswap.h> #include <sys/stat.h> - +#include <linux/zalloc.h> static bool check_need_swap (int file_endian) {
tools/perf/util/symbol.c +1 -0
@@ -26,6 +26,7 @@#include "header.h" #include "path.h" #include <linux/ctype.h> +#include <linux/zalloc.h> #include <elf.h> #include <limits.h>
tools/perf/util/syscalltbl.c +1 -1
@@ -10,9 +10,9 @@#include <linux/compiler.h> #ifdef HAVE_SYSCALL_TABLE_SUPPORT +#include <linux/zalloc.h> #include <string.h> #include "string2.h" -#include "util.h" #if defined(__x86_64__)#include <asm/syscalls_64.c>
tools/perf/util/thread-stack.c +1 -1
@@ -7,13 +7,13 @@#include <linux/rbtree.h> #include <linux/list.h> #include <linux/log2.h> +#include <linux/zalloc.h> #include <errno.h> #include <stdlib.h> #include "thread.h" #include "event.h" #include "machine.h" #include "env.h" -#include "util.h" #include "debug.h" #include "symbol.h" #include "comm.h"
tools/perf/util/thread.c +1 -1
@@ -5,10 +5,10 @@#include <stdio.h> #include <string.h> #include <linux/kernel.h> +#include <linux/zalloc.h> #include "session.h" #include "thread.h" #include "thread-stack.h" -#include "util.h" #include "debug.h" #include "namespaces.h" #include "comm.h"
tools/perf/util/thread_map.c +1 -1
@@ -13,9 +13,9 @@#include <string.h> #include <api/fs/fs.h> #include <linux/string.h> +#include <linux/zalloc.h> #include "asm/bug.h" #include "thread_map.h" -#include "util.h" #include "debug.h" #include "event.h"
tools/perf/util/trace-event-info.c +1 -0
@@ -18,6 +18,7 @@#include <stdbool.h> #include <linux/list.h> #include <linux/kernel.h> +#include <linux/zalloc.h> #include "../perf.h" #include "trace-event.h"
tools/perf/util/trace-event-scripting.c +1 -1
@@ -12,8 +12,8 @@#include "../perf.h" #include "debug.h" -#include "util.h" #include "trace-event.h" +#include <linux/zalloc.h> struct scripting_context *scripting_context;
tools/perf/util/unwind-libdw.c +1 -0
@@ -12,6 +12,7 @@#include "symbol.h" #include "thread.h" #include <linux/types.h> +#include <linux/zalloc.h> #include "event.h" #include "perf_regs.h" #include "callchain.h"
tools/perf/util/util.h +0 -9
@@ -9,8 +9,6 @@#include <fcntl.h> #include <stdbool.h> #include <stddef.h> -#include <stdlib.h> -#include <stdarg.h> #include <linux/compiler.h> #include <sys/types.h>
@@ -18,13 +16,6 @@void usage (const char *err)__noreturn ; void die(const char *err, ...) __noreturn __printf(1, 2); -static inline void *zalloc (size_t size) -{ -return calloc (1 , size); -} - -#define zfree (ptr) ({ free(*ptr); *ptr = NULL; }) -struct dirent ;struct nsinfo ;struct strlist ;
tools/perf/util/values.c +1 -1
@@ -3,8 +3,8 @@#include <stdio.h> #include <stdlib.h> #include <errno.h> +#include <linux/zalloc.h> -#include "util.h" #include "values.h" #include "debug.h"
tools/perf/util/vdso.c +1 -0
@@ -16,6 +16,7 @@#include "machine.h" #include "thread.h" #include "linux/string.h" +#include <linux/zalloc.h> #include "debug.h" /*
tools/perf/util/xyarray.c +1 -1
@@ -1,8 +1,8 @@// SPDX-License-Identifier: GPL-2.0 #include "xyarray.h" -#include "util.h" #include <stdlib.h> #include <string.h> +#include <linux/zalloc.h> struct xyarray *xyarray__new (int xlen,int ylen,size_t entry_size) {
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 14/25 perf tools: Use zfree() where applicable
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
In places where the equivalent was already being done, i.e.:
free(a); a = NULL;
And in placs where struct members are being freed so that if we have some erroneous reference to its struct, then accesses to freed members will result in segfaults, which we can detect faster than use after free to areas that may still have something seemingly valid.
--- tools/perf/bench/futex-hash.c | 3 +- tools/perf/bench/futex-lock-pi.c | 3 +- tools/perf/builtin-record.c | 4 +- tools/perf/builtin-stat.c | 4 +- tools/perf/tests/dwarf-unwind.c | 5 ++- tools/perf/tests/expr.c | 3 +- tools/perf/tests/mem2node.c | 3 +- tools/perf/tests/thread-map.c | 3 +- tools/perf/ui/browsers/res_sample.c | 6 +-- tools/perf/ui/browsers/scripts.c | 4 +- tools/perf/util/annotate.c | 3 +- tools/perf/util/auxtrace.c | 5 +-- tools/perf/util/cgroup.c | 2 +- tools/perf/util/cputopo.c | 2 +- tools/perf/util/cs-etm.c | 5 +-- tools/perf/util/data-convert-bt.c | 2 +- tools/perf/util/data.c | 2 +- tools/perf/util/env.c | 8 ++-- tools/perf/util/event.c | 2 +- tools/perf/util/header.c | 6 +-- tools/perf/util/hist.c | 14 +++---- tools/perf/util/jitdump.c | 7 ++-- tools/perf/util/llvm-utils.c | 3 +- tools/perf/util/machine.c | 4 +- tools/perf/util/metricgroup.c | 9 +++-- tools/perf/util/probe-event.c | 51 +++++++++++------------- tools/perf/util/s390-cpumsf.c | 7 ++-- tools/perf/util/srccode.c | 9 +++-- tools/perf/util/stat-shadow.c | 3 +- tools/perf/util/stat.c | 2 +- tools/perf/util/symbol-elf.c | 10 ++--- tools/perf/util/thread_map.c | 2 +- tools/perf/util/unwind-libunwind-local.c | 3 +- 33 files changed, 100 insertions(+), 99 deletions(-)
tools/perf/bench/futex-hash.c +2 -1
@@ -18,6 +18,7 @@#include <stdlib.h> #include <linux/compiler.h> #include <linux/kernel.h> +#include <linux/zalloc.h> #include <sys/time.h> #include "../util/stat.h"
@@ -214,7 +215,7 @@ int bench_futex_hash(int argc, const char **argv) &worker[i].futex[nfutexes-1], t); } -free (worker[i].futex); +zfree (&worker[i].futex); }print_summary ();
tools/perf/bench/futex-lock-pi.c +2 -1
@@ -12,6 +12,7 @@#include <subcmd/parse-options.h> #include <linux/compiler.h> #include <linux/kernel.h> +#include <linux/zalloc.h> #include <errno.h> #include "bench.h" #include "futex.h"
@@ -217,7 +218,7 @@ int bench_futex_lock_pi(int argc, const char **argv) worker[i].tid, worker[i].futex, t);if (multi) -free (worker[i].futex); +zfree (&worker[i].futex); }print_summary ();
tools/perf/builtin-record.c +2 -2
@@ -11,7 +11,6 @@#include "perf.h" #include "util/build-id.h" -#include "util/util.h" #include <subcmd/parse-options.h> #include "util/parse-events.h" #include "util/config.h"
@@ -54,6 +53,7 @@#include <sys/mman.h> #include <sys/wait.h> #include <linux/time64.h> +#include <linux/zalloc.h> struct switch_output {bool enabled;
@@ -1110,7 +1110,7 @@ record__switch_output(struct record *rec, bool at_exit) rec->switch_output.cur_file = n;if (rec->switch_output.filenames[n]) {remove (rec->switch_output.filenames[n]); -free (rec->switch_output.filenames[n]); +zfree (&rec->switch_output.filenames[n]); } rec->switch_output.filenames[n] = new_filename; }else {
tools/perf/builtin-stat.c +2 -2
@@ -1586,7 +1586,7 @@ static void runtime_stat_delete(struct perf_stat_config *config)for (i =0 ; i < config->stats_num; i++)runtime_stat__exit (&config->stats[i]); -free (config->stats); +zfree (&config->stats); }static const char *const stat_report_usage[] = {
@@ -2003,7 +2003,7 @@ int cmd_stat(int argc, const char **argv)perf_stat__exit_aggr_mode ();perf_evlist__free_stats (evsel_list); out: -free (stat_config.walltime_run); +zfree (&stat_config.walltime_run);if (smi_cost && smi_reset)sysfs__write_int (FREEZE_ON_SMI_PATH ,0 );
tools/perf/tests/dwarf-unwind.c +3 -2
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/compiler.h> #include <linux/types.h> +#include <linux/zalloc.h> #include <inttypes.h> #include <unistd.h> #include "tests.h"
@@ -115,8 +116,8 @@ noinline int test_dwarf_unwind__thread(struct thread *thread) } out: -free (sample.user_stack.data); -free (sample.user_regs.regs); +zfree (&sample.user_stack.data); +zfree (&sample.user_regs.regs);return err; }
tools/perf/tests/expr.c +2 -1
@@ -3,6 +3,7 @@#include "util/expr.h" #include "tests.h" #include <stdlib.h> +#include <linux/zalloc.h> static int test (struct parse_ctx *ctx,const char *e,double val2) {
@@ -58,7 +59,7 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused)TEST_ASSERT_VAL ("find other" , other[3 ] ==NULL );for (i =0 ; i < num_other; i++) -free ((void *)other[i]); +zfree (&other[i]);free ((void *)other);return 0 ;
tools/perf/tests/mem2node.c +2 -1
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/compiler.h> #include <linux/bitmap.h> +#include <linux/zalloc.h> #include "cpumap.h" #include "mem2node.h" #include "tests.h"
@@ -67,7 +68,7 @@ int test__mem2node(struct test *t __maybe_unused, int subtest __maybe_unused)T ("failed: mem2node__node" ,-1 ==mem2node__node (&map,0x1050 ));for (i =0 ; i <ARRAY_SIZE (nodes); i++) -free (nodes[i].set); +zfree (&nodes[i].set);mem2node__exit (&map);return 0 ;
tools/perf/tests/thread-map.c +2 -1
@@ -6,6 +6,7 @@#include "tests.h" #include "thread_map.h" #include "debug.h" +#include <linux/zalloc.h> #define NAME (const char *) "perf"#define NAMEUL (unsigned long) NAME
@@ -133,7 +134,7 @@ int test__thread_map_remove(struct test *test __maybe_unused, int subtest __mayb thread_map__remove(threads, 0));for (i =0 ; i < threads->nr; i++) -free (threads->map[i].comm); +zfree (&threads->map[i].comm);free (threads);return 0 ;
tools/perf/ui/browsers/res_sample.c +3 -3
@@ -1,6 +1,5 @@// SPDX-License-Identifier: GPL-2.0 /* Display a menu with individual samples to browse with perf script */ -#include "util.h" #include "hist.h" #include "evsel.h" #include "hists.h"
@@ -8,6 +7,7 @@#include "config.h" #include "time-utils.h" #include <linux/time64.h> +#include <linux/zalloc.h> static u64 context_len =10 *NSEC_PER_MSEC ;
@@ -46,14 +46,14 @@ int res_sample_browse(struct res_sample *res_samples, int num_res,if (asprintf (&names[i],"%s: CPU %d tid %d" , tbuf, res_samples[i].cpu, res_samples[i].tid) <0 ) {while (--i >=0 ) -free (names[i]); +zfree (&names[i]);free (names);return -1 ; } } choice =ui__popup_menu (num_res, names);for (i =0 ; i < num_res; i++) -free (names[i]); +zfree (&names[i]);free (names);if (choice <0 || choice >= num_res)
tools/perf/ui/browsers/scripts.c +2 -2
@@ -1,12 +1,12 @@// SPDX-License-Identifier: GPL-2.0 #include "../../util/sort.h" -#include "../../util/util.h" #include "../../util/hist.h" #include "../../util/debug.h" #include "../../util/symbol.h" #include "../browser.h" #include "../libslang.h" #include "config.h" +#include <linux/zalloc.h> #define SCRIPT_NAMELEN 128#define SCRIPT_MAX_NO 64
@@ -142,7 +142,7 @@ static int list_scripts(char *script_name, bool *custom, out:free (buf);for (i =0 ; i < max_std; i++) -free (paths[i]); +zfree (&paths[i]);return ret; }
tools/perf/util/annotate.c +1 -2
@@ -1235,8 +1235,7 @@ void disasm_line__free(struct disasm_line *dl) dl->ins.ops->free (&dl->ops); else ins__delete(&dl->ops); -free ((void *)dl->ins.name); - dl->ins.name =NULL ; +zfree (&dl->ins.name);annotation_line__delete (&dl->al); }
tools/perf/util/auxtrace.c +2 -3
@@ -1413,7 +1413,7 @@ void auxtrace_cache__free(struct auxtrace_cache *c)return ;auxtrace_cache__drop (c); -free (c->hashtable); +zfree (&c->hashtable);free (c); }
@@ -1459,12 +1459,11 @@ void *auxtrace_cache__lookup(struct auxtrace_cache *c, u32 key)static void addr_filter__free_str (struct addr_filter *filt) { -free (filt->str); +zfree (&filt->str); filt->action =NULL ; filt->sym_from =NULL ; filt->sym_to =NULL ; filt->filename =NULL ; - filt->str =NULL ; }static struct addr_filter *addr_filter__new (void )
tools/perf/util/cgroup.c +1 -1
@@ -124,7 +124,7 @@ static struct cgroup *cgroup__new(const char *name)return cgroup; out_free_name: -free (cgroup->name); +zfree (&cgroup->name); out_err:free (cgroup);return NULL ;
tools/perf/util/cputopo.c +1 -1
@@ -344,7 +344,7 @@ void numa_topology__delete(struct numa_topology *tp)u32 i;for (i =0 ; i < tp->nr; i++) -free (tp->nodes[i].cpus); +zfree (&tp->nodes[i].cpus);free (tp); }
tools/perf/util/cs-etm.c +2 -3
@@ -555,8 +555,7 @@ static void cs_etm__free_traceid_queues(struct cs_etm_queue *etmq) etmq->traceid_queues_list =NULL ;/* finally free the traceid_queues array */ -free (etmq->traceid_queues); - etmq->traceid_queues =NULL ; +zfree (&etmq->traceid_queues); }static void cs_etm__free_queue (void *priv)
@@ -2569,7 +2568,7 @@ int cs_etm__process_auxtrace_info(union perf_event *event, err_free_metadata:/* No need to check @metadata[j], free(NULL) is supported */ for (j =0 ; j < num_cpu; j++) -free (metadata[j]); +zfree (&metadata[j]);zfree (&metadata); err_free_traceid_list:intlist__delete (traceid_list);
tools/perf/util/data-convert-bt.c +1 -1
@@ -1353,7 +1353,7 @@ static void free_streams(struct ctf_writer *cw)for (cpu =0 ; cpu < cw->stream_cnt; cpu++)ctf_stream__delete (cw->stream[cpu]); -free (cw->stream); +zfree (&cw->stream); } static int ctf_writer__setup_env(struct ctf_writer *cw,
tools/perf/util/data.c +1 -1
@@ -21,7 +21,7 @@ static void close_dir(struct perf_data_file *files, int nr) {while (--nr >=1 ) {close (files[nr].fd); -free (files[nr].path); +zfree (&files[nr].path); }free (files); }
tools/perf/util/env.c +4 -4
@@ -187,7 +187,7 @@ void perf_env__exit(struct perf_env *env)zfree (&env->caches);for (i =0 ; i < env->nr_memory_nodes; i++) -free (env->memory_nodes[i].set); +zfree (&env->memory_nodes[i].set);zfree (&env->memory_nodes); }
@@ -287,9 +287,9 @@ int perf_env__nr_cpus_avail(struct perf_env *env)void cpu_cache_level__free (struct cpu_cache_level *cache) { -free (cache->type); -free (cache->map); -free (cache->size); +zfree (&cache->type); +zfree (&cache->map); +zfree (&cache->size); }/*
tools/perf/util/event.c +1 -1
@@ -856,7 +856,7 @@ int perf_event__synthesize_threads(struct perf_tool *tool,free (synthesize_threads); free_dirent:for (i =0 ; i < n; i++) -free (dirent[i]); +zfree (&dirent[i]);free (dirent);return err;
tools/perf/util/header.c +3 -3
@@ -1052,7 +1052,7 @@ static int cpu_cache_level__read(struct cpu_cache_level *cache, u32 cpu, u16 levscnprintf (file,PATH_MAX ,"%s/size" , path);if (sysfs__read_str (file, &cache->size, &len)) { -free (cache->type); +zfree (&cache->type);return -1 ; }
@@ -1061,8 +1061,8 @@ static int cpu_cache_level__read(struct cpu_cache_level *cache, u32 cpu, u16 levscnprintf (file,PATH_MAX ,"%s/shared_cpu_list" , path);if (sysfs__read_str (file, &cache->map, &len)) { -free (cache->map); -free (cache->type); +zfree (&cache->map); +zfree (&cache->type);return -1 ; }
tools/perf/util/hist.c +7 -7
@@ -472,16 +472,16 @@ static int hist_entry__init(struct hist_entry *he,return 0 ; err_srcline: -free (he->srcline); +zfree (&he->srcline); err_rawdata: -free (he->raw_data); +zfree (&he->raw_data); err_infos:if (he->branch_info) {map__put (he->branch_info->from.map);map__put (he->branch_info->to.map); -free (he->branch_info); +zfree (&he->branch_info); }if (he->mem_info) {map__put (he->mem_info->iaddr.map);
@@ -489,7 +489,7 @@ static int hist_entry__init(struct hist_entry *he, } err:map__zput (he->ms.map); -free (he->stat_acc); +zfree (&he->stat_acc);return -ENOMEM ; }
@@ -1254,10 +1254,10 @@ void hist_entry__delete(struct hist_entry *he)zfree (&he->stat_acc);free_srcline (he->srcline);if (he->srcfile && he->srcfile[0 ]) -free (he->srcfile); +zfree (&he->srcfile);free_callchain (he->callchain); -free (he->trace_output); -free (he->raw_data); +zfree (&he->trace_output); +zfree (&he->raw_data); ops->free (he); }
tools/perf/util/jitdump.c +3 -4
@@ -29,6 +29,7 @@#include "../builtin.h" #include <linux/ctype.h> +#include <linux/zalloc.h> struct jit_buf_desc {struct perf_data *output;
@@ -431,14 +432,12 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr) jd->unwinding_data, jd->eh_frame_hdr_size, jd->unwinding_size);if (jd->debug_data && jd->nr_debug_entries) { -free (jd->debug_data); - jd->debug_data =NULL ; +zfree (&jd->debug_data); jd->nr_debug_entries =0 ; }if (jd->unwinding_data && jd->eh_frame_hdr_size) { -free (jd->unwinding_data); - jd->unwinding_data =NULL ; +zfree (&jd->unwinding_data); jd->eh_frame_hdr_size =0 ; jd->unwinding_mapped_size =0 ; jd->unwinding_size =0 ;
tools/perf/util/llvm-utils.c +1 -2
@@ -353,8 +353,7 @@ void llvm__get_kbuild_opts(char **kbuild_dir, char **kbuild_include_opts)" \toption in [llvm] to \"\" to suppress this detection.\n\n" , *kbuild_dir); -free (*kbuild_dir); - *kbuild_dir =NULL ; +zfree (kbuild_dir); goto errout; }
tools/perf/util/machine.c +2 -2
@@ -810,7 +810,7 @@ struct map *machine__findnew_module_map(struct machine *machine, u64 start, out:/* put the dso here, corresponding to machine__findnew_module_dso */ dso__put (dso); -free (m.name); +zfree (&m.name);return map; }
@@ -1350,7 +1350,7 @@ static int map_groups__set_modules_path_dir(struct map_groups *mg,if (m.kmod) ret =map_groups__set_module_path (mg, path, &m); -free (m.name); +zfree (&m.name);if (ret) goto out;
tools/perf/util/metricgroup.c +5 -4
@@ -18,6 +18,7 @@#include "strlist.h" #include <assert.h> #include <linux/ctype.h> +#include <linux/zalloc.h> struct metric_event *metricgroup__lookup(struct rblist *metric_events, struct perf_evsel *evsel,
@@ -235,7 +236,7 @@ static struct rb_node *mep_new(struct rblist *rl __maybe_unused, goto out_name;return &me->nd; out_name: -free ((char *)me->name); +zfree (&me->name); out_me:free (me);return NULL ;
@@ -263,7 +264,7 @@ static void mep_delete(struct rblist *rl __maybe_unused, struct mep *me = container_of(nd, struct mep, nd);strlist__delete (me->metrics); -free ((void *)me->name); +zfree (&me->name);free (me); }
@@ -489,8 +490,8 @@ static void metricgroup__free_egroups(struct list_head *group_list) list_for_each_entry_safe (eg, egtmp, group_list, nd) {for (i =0 ; i < eg->idnum; i++) -free ((char *)eg->ids[i]); -free (eg->ids); +zfree (&eg->ids[i]); +zfree (&eg->ids);free (eg); } }
tools/perf/util/probe-event.c +24 -27
98 lines not on this page · raw message
tools/perf/util/s390-cpumsf.c +3 -4
@@ -1044,7 +1044,7 @@ static void s390_cpumsf_free(struct perf_session *session)auxtrace_heap__free (&sf->heap);s390_cpumsf_free_queues (session); session->auxtrace =NULL ; -free (sf->logdir); +zfree (&sf->logdir);free (sf); }
@@ -1101,8 +1101,7 @@ static int s390_cpumsf__config(const char *var, const char *value, void *cb)if (rc ==-1 || !S_ISDIR (stbuf.st_mode)) {pr_err ("Missing auxtrace log directory %s," " continue with current directory...\n" , value); -free (sf->logdir); - sf->logdir =NULL ; +zfree (&sf->logdir); }return 1 ; }
@@ -1162,7 +1161,7 @@ int s390_cpumsf_process_auxtrace_info(union perf_event *event,auxtrace_queues__free (&sf->queues); session->auxtrace =NULL ; err_free: -free (sf->logdir); +zfree (&sf->logdir);free (sf);return err; }
tools/perf/util/srccode.c +5 -4
@@ -4,7 +4,8 @@* Copyright (c) 2017, Intel Corporation. * Author: Andi Kleen */ -#include "linux/list.h" +#include <linux/list.h> +#include <linux/zalloc.h> #include <stdlib.h> #include <sys/mman.h> #include <sys/stat.h>
@@ -86,8 +87,8 @@ static void free_srcfile(struct srcfile *sf)hlist_del (&sf->hash_nd); map_total_sz -= sf->maplen;munmap (sf->map, sf->maplen); -free (sf->lines); -free (sf->fn); +zfree (&sf->lines); +zfree (&sf->fn);free (sf); num_srcfiles--; }
@@ -153,7 +154,7 @@ static struct srcfile *find_srcfile(char *fn) out_map:munmap (h->map, sz); out_fn: -free (h->fn); +zfree (&h->fn); out_h:free (h);return NULL ;
tools/perf/util/stat-shadow.c +2 -1
@@ -8,6 +8,7 @@#include "evlist.h" #include "expr.h" #include "metricgroup.h" +#include <linux/zalloc.h> /* * AGGR_GLOBAL: Use CPU 0
@@ -775,7 +776,7 @@ static void generic_metric(struct perf_stat_config *config,print_metric (config, ctxp,NULL ,NULL ,"" ,0 );for (i =1 ; i < pctx.num_ids; i++) -free ((void *)pctx.ids[i].name); +zfree (&pctx.ids[i].name); } void perf_stat__print_shadow_stats(struct perf_stat_config *config,
tools/perf/util/stat.c +1 -1
@@ -133,7 +133,7 @@ static void perf_evsel__free_stat_priv(struct perf_evsel *evsel)struct perf_stat_evsel *ps = evsel->stats;if (ps) -free (ps->group_data); +zfree (&ps->group_data);zfree (&evsel->stats); }
tools/perf/util/symbol-elf.c +5 -5
@@ -2133,11 +2133,11 @@ static int populate_sdt_note(Elf **elf, const char *data, size_t len,return 0 ; out_free_args: -free (tmp->args); +zfree (&tmp->args); out_free_name: -free (tmp->name); +zfree (&tmp->name); out_free_prov: -free (tmp->provider); +zfree (&tmp->provider); out_free_note:free (tmp); out_err:
@@ -2253,8 +2253,8 @@ int cleanup_sdt_note_list(struct list_head *sdt_notes)list_for_each_entry_safe (pos, tmp, sdt_notes, note_list) {list_del (&pos->note_list); -free (pos->name); -free (pos->provider); +zfree (&pos->name); +zfree (&pos->provider);free (pos); nr_free++; }
tools/perf/util/thread_map.c +1 -1
@@ -480,7 +480,7 @@ int thread_map__remove(struct thread_map *threads, int idx)/* * Free the 'idx' item and shift the rest up. */ -free (threads->map[idx].comm); +zfree (&threads->map[idx].comm);for (i = idx; i < threads->nr -1 ; i++) threads->map[i] = threads->map[i +1 ];
tools/perf/util/unwind-libunwind-local.c +2 -1
@@ -25,6 +25,7 @@#include <unistd.h> #include <sys/mman.h> #include <linux/list.h> +#include <linux/zalloc.h> #ifndef REMOTE_UNWIND_LIBUNWIND #include <libunwind.h> #include <libunwind-ptrace.h>
@@ -345,7 +346,7 @@ static int read_unwind_spec_debug_frame(struct dso *dso, __func__, dso->symsrc_filename, debuglink); -free (dso->symsrc_filename); +zfree (&dso->symsrc_filename); } dso->symsrc_filename = debuglink; }else {
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 15/25 perf tools: Use list_del_init() more thorougly
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
To allow for destructors to check if they're operating on a object still in a list, and to avoid going from use after free list entries into still valid, or even also other already removed from list entries.
--- tools/perf/builtin-ftrace.c | 2 +- tools/perf/builtin-lock.c | 8 ++++---- tools/perf/pmu-events/jevents.c | 2 +- tools/perf/tests/switch-tracking.c | 2 +- tools/perf/ui/gtk/annotate.c | 2 +- tools/perf/util/annotate.c | 4 ++-- tools/perf/util/auxtrace.c | 4 ++-- tools/perf/util/bpf-loader.c | 2 +- tools/perf/util/call-path.c | 2 +- tools/perf/util/callchain.c | 10 +++++----- tools/perf/util/db-export.c | 4 ++-- tools/perf/util/dso.c | 2 +- tools/perf/util/evsel.c | 2 +- tools/perf/util/hist.c | 4 ++-- tools/perf/util/ordered-events.c | 6 +++--- tools/perf/util/parse-events.c | 2 +- tools/perf/util/pmu.c | 2 +- tools/perf/util/probe-event.c | 2 +- tools/perf/util/s390-cpumsf.c | 2 +- tools/perf/util/srccode.c | 2 +- tools/perf/util/symbol-elf.c | 6 +++--- tools/perf/util/thread.c | 4 ++-- 22 files changed, 38 insertions(+), 38 deletions(-)
tools/perf/builtin-ftrace.c +1 -1
@@ -431,7 +431,7 @@ static void delete_filter_func(struct list_head *head)struct filter_entry *pos, *tmp;list_for_each_entry_safe (pos, tmp, head, list) { -list_del (&pos->list); +list_del_init (&pos->list);free (pos); } }
tools/perf/builtin-lock.c +4 -4
@@ -454,7 +454,7 @@ static int report_lock_acquire_event(struct perf_evsel *evsel,/* broken lock sequence, discard it */ ls->discard =1 ; bad_hist[BROKEN_ACQUIRE ]++; -list_del (&seq->list); +list_del_init (&seq->list);free (seq); goto end;default :
@@ -515,7 +515,7 @@ static int report_lock_acquired_event(struct perf_evsel *evsel,/* broken lock sequence, discard it */ ls->discard =1 ; bad_hist[BROKEN_ACQUIRED ]++; -list_del (&seq->list); +list_del_init (&seq->list);free (seq); goto end;default :
@@ -570,7 +570,7 @@ static int report_lock_contended_event(struct perf_evsel *evsel,/* broken lock sequence, discard it */ ls->discard =1 ; bad_hist[BROKEN_CONTENDED ]++; -list_del (&seq->list); +list_del_init (&seq->list);free (seq); goto end;default :
@@ -639,7 +639,7 @@ static int report_lock_release_event(struct perf_evsel *evsel, ls->nr_release++; free_seq: -list_del (&seq->list); +list_del_init (&seq->list);free (seq); end:return 0 ;
tools/perf/pmu-events/jevents.c +1 -1
@@ -407,7 +407,7 @@ static void free_arch_std_events(void)list_for_each_entry_safe (es, next, &arch_std_events, list) {FOR_ALL_EVENT_STRUCT_FIELDS (FREE_EVENT_FIELD ); -list_del (&es->list); +list_del_init (&es->list);free (es); } }
tools/perf/tests/switch-tracking.c +1 -1
@@ -238,7 +238,7 @@ static void free_event_nodes(struct list_head *events)while (!list_empty (events)) { node = list_entry(events->next, struct event_node, list); -list_del (&node->list); +list_del_init (&node->list);free (node); } }
tools/perf/ui/gtk/annotate.c +1 -1
@@ -152,7 +152,7 @@ static int perf_gtk__annotate_symbol(GtkWidget *window, struct symbol *sym,gtk_container_add (GTK_CONTAINER (window), view);list_for_each_entry_safe (pos, n, ¬es->src->source, al.node) { -list_del (&pos->al.node); +list_del_init (&pos->al.node);disasm_line__free (pos); }
tools/perf/util/annotate.c +2 -2
@@ -1586,7 +1586,7 @@ static void delete_last_nop(struct symbol *sym)return ; } -list_del (&dl->al.node); +list_del_init (&dl->al.node);disasm_line__free (dl); } }
@@ -2463,7 +2463,7 @@ void annotated_source__purge(struct annotated_source *as)struct annotation_line *al, *n;list_for_each_entry_safe (al, n, &as->source, node) { -list_del (&al->node); +list_del_init (&al->node);disasm_line__free (disasm_line (al)); } }
tools/perf/util/auxtrace.c +2 -2
@@ -408,7 +408,7 @@ void auxtrace_queues__free(struct auxtrace_queues *queues) buffer =list_entry (queues->queue_array[i].head.next, struct auxtrace_buffer, list); -list_del (&buffer->list); +list_del_init (&buffer->list);auxtrace_buffer__free (buffer); } }
@@ -612,7 +612,7 @@ void auxtrace_index__free(struct list_head *head)struct auxtrace_index *auxtrace_index, *n;list_for_each_entry_safe (auxtrace_index, n, head, list) { -list_del (&auxtrace_index->list); +list_del_init (&auxtrace_index->list);free (auxtrace_index); } }
tools/perf/util/bpf-loader.c +1 -1
@@ -829,7 +829,7 @@ static void bpf_map_op__delete(struct bpf_map_op *op) {if (!list_empty (&op->list)) -list_del (&op->list); +list_del_init (&op->list);if (op->key_type ==BPF_MAP_KEY_RANGES )parse_events__clear_array (&op->k.array);free (op);
tools/perf/util/call-path.c +1 -1
@@ -40,7 +40,7 @@ void call_path_root__free(struct call_path_root *cpr)struct call_path_block *pos, *n;list_for_each_entry_safe (pos, n, &cpr->blocks, node) { -list_del (&pos->node); +list_del_init (&pos->node);free (pos); }free (cpr);
tools/perf/util/callchain.c +5 -5
@@ -636,7 +636,7 @@ add_child(struct callchain_node *parent,struct callchain_list *call, *tmp;list_for_each_entry_safe (call, tmp, &new->val, list) { -list_del (&call->list); +list_del_init (&call->list);map__zput (call->ms.map);free (call); }
@@ -1002,7 +1002,7 @@ merge_chain_branch(struct callchain_cursor *cursor,callchain_cursor_append (cursor, list->ip, list->ms.map, list->ms.sym, false,NULL ,0 ,0 ,0 , list->srcline); -list_del (&list->list); +list_del_init (&list->list);map__zput (list->ms.map);free (list); }
@@ -1453,13 +1453,13 @@ static void free_callchain_node(struct callchain_node *node)struct rb_node *n;list_for_each_entry_safe (list, tmp, &node->parent_val, list) { -list_del (&list->list); +list_del_init (&list->list);map__zput (list->ms.map);free (list); }list_for_each_entry_safe (list, tmp, &node->val, list) { -list_del (&list->list); +list_del_init (&list->list);map__zput (list->ms.map);free (list); }
@@ -1544,7 +1544,7 @@ int callchain_node__make_parent_list(struct callchain_node *node) out:list_for_each_entry_safe (chain, new, &head, list) { -list_del (&chain->list); +list_del_init (&chain->list);map__zput (chain->ms.map);free (chain); }
tools/perf/util/db-export.c +2 -2
@@ -34,7 +34,7 @@ static int db_export__deferred(struct db_export *dbe) de = list_entry(dbe->deferred.next, struct deferred_export, node); err = dbe->export_comm (dbe, de->comm); -list_del (&de->node); +list_del_init (&de->node);free (de);if (err)return err;
@@ -50,7 +50,7 @@ static void db_export__free_deferred(struct db_export *dbe)while (!list_empty (&dbe->deferred)) { de = list_entry(dbe->deferred.next, struct deferred_export, node); -list_del (&de->node); +list_del_init (&de->node);free (de); } }
tools/perf/util/dso.c +1 -1
@@ -434,7 +434,7 @@ static void dso__list_add(struct dso *dso)static void dso__list_del (struct dso *dso) { -list_del (&dso->data.open_entry); +list_del_init (&dso->data.open_entry);WARN_ONCE (dso__data_open_cnt <=0 ,"DSO data fd counter out of bounds." ); dso__data_open_cnt--;
tools/perf/util/evsel.c +1 -1
@@ -1298,7 +1298,7 @@ static void perf_evsel__free_config_terms(struct perf_evsel *evsel)struct perf_evsel_config_term *term, *h;list_for_each_entry_safe (term, h, &evsel->config_terms, list) { -list_del (&term->list); +list_del_init (&term->list);free (term); } }
tools/perf/util/hist.c +2 -2
@@ -2741,10 +2741,10 @@ static void hists_evsel__exit(struct perf_evsel *evsel)list_for_each_entry_safe (node, tmp, &hists->hpp_formats, list) {perf_hpp_list__for_each_format_safe (&node->hpp, fmt, pos) { -list_del (&fmt->list); +list_del_init (&fmt->list);free (fmt); } -list_del (&node->list); +list_del_init (&node->list);free (node); } }
tools/perf/util/ordered-events.c +3 -3
@@ -138,7 +138,7 @@ static struct ordered_event *alloc_event(struct ordered_events *oe,if (!list_empty (cache)) { new = list_entry(cache->next, struct ordered_event, list); -list_del (&new->list); +list_del_init (&new->list); }else if (oe->buffer) { new = &oe->buffer->event[oe->buffer_idx];if (++oe->buffer_idx ==MAX_SAMPLE_BUFFER )
@@ -394,13 +394,13 @@ void ordered_events__free(struct ordered_events *oe)* yet, we need to free only allocated ones ... */ if (oe->buffer) { -list_del (&oe->buffer->list); +list_del_init (&oe->buffer->list);ordered_events_buffer__free (oe->buffer, oe->buffer_idx, oe); }/* ... and continue with the rest */ list_for_each_entry_safe (buffer, tmp, &oe->to_free, list) { -list_del (&buffer->list); +list_del_init (&buffer->list);ordered_events_buffer__free (buffer,MAX_SAMPLE_BUFFER , oe); } }
tools/perf/util/parse-events.c +1 -1
@@ -652,7 +652,7 @@ static int add_bpf_event(const char *group, const char *event, int fd,pr_debug ("Failed to add BPF event %s:%s\n" , group, event);list_for_each_entry_safe (evsel, tmp, &new_evsels, node) { -list_del (&evsel->node); +list_del_init (&evsel->node);perf_evsel__delete (evsel); }return err;
tools/perf/util/pmu.c +1 -1
@@ -1245,7 +1245,7 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, info->metric_expr = alias->metric_expr; info->metric_name = alias->metric_name; -list_del (&term->list); +list_del_init (&term->list);free (term); }
tools/perf/util/probe-event.c +1 -1
@@ -2333,7 +2333,7 @@ static void kprobe_blacklist__delete(struct list_head *blacklist)while (!list_empty (blacklist)) { node =list_first_entry (blacklist, struct kprobe_blacklist_node, list); -list_del (&node->list); +list_del_init (&node->list);zfree (&node->symbol);free (node); }
tools/perf/util/s390-cpumsf.c +1 -1
@@ -756,7 +756,7 @@ static int s390_cpumsf_run_decoder(struct s390_cpumsf_queue *sfq,*/ if (err) { sfq->buffer =NULL ; -list_del (&buffer->list); +list_del_init (&buffer->list);auxtrace_buffer__free (buffer);if (err >0 )/* Buffer done, no error */ err =0 ;
tools/perf/util/srccode.c +1 -1
@@ -83,7 +83,7 @@ static void fill_lines(char **lines, int maxline, char *map, int maplen)static void free_srcfile (struct srcfile *sf) { -list_del (&sf->nd); +list_del_init (&sf->nd);hlist_del (&sf->hash_nd); map_total_sz -= sf->maplen;munmap (sf->map, sf->maplen);
tools/perf/util/symbol-elf.c +3 -3
@@ -1478,7 +1478,7 @@ static void kcore_copy__free_phdrs(struct kcore_copy_info *kci)struct phdr_data *p, *tmp;list_for_each_entry_safe (p, tmp, &kci->phdrs, node) { -list_del (&p->node); +list_del_init (&p->node);free (p); } }
@@ -1501,7 +1501,7 @@ static void kcore_copy__free_syms(struct kcore_copy_info *kci)struct sym_data *s, *tmp;list_for_each_entry_safe (s, tmp, &kci->syms, node) { -list_del (&s->node); +list_del_init (&s->node);free (s); } }
@@ -2252,7 +2252,7 @@ int cleanup_sdt_note_list(struct list_head *sdt_notes)int nr_free =0 ;list_for_each_entry_safe (pos, tmp, sdt_notes, note_list) { -list_del (&pos->note_list); +list_del_init (&pos->note_list);zfree (&pos->name);zfree (&pos->provider);free (pos);
tools/perf/util/thread.c +2 -2
@@ -93,14 +93,14 @@ void thread__delete(struct thread *thread)down_write (&thread->namespaces_lock);list_for_each_entry_safe (namespaces, tmp_namespaces, &thread->namespaces_list, list) { -list_del (&namespaces->list); +list_del_init (&namespaces->list);namespaces__free (namespaces); }up_write (&thread->namespaces_lock);down_write (&thread->comm_lock);list_for_each_entry_safe (comm, tmp_comm, &thread->comm_list, list) { -list_del (&comm->list); +list_del_init (&comm->list);comm__free (comm); }up_write (&thread->comm_lock);
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 16/25 perf metricgroup: Add missing list_del_init() when flushing egroups list
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
So that at the end each of the entries have its list node struct cleared and the egroup list head ends emptied.
--- tools/perf/util/metricgroup.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/metricgroup.c +1 -0
@@ -492,6 +492,7 @@ static void metricgroup__free_egroups(struct list_head *group_list)for (i =0 ; i < eg->idnum; i++)zfree (&eg->ids[i]);zfree (&eg->ids); +list_del_init (&eg->nd);free (eg); } }
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 17/25 perf parse-events: Remove unused variable 'i'
In reply to Arnaldo Carvalho de MeloFrom: Luke Mujica <[email protected]>
Remove the 'int i' because it is declared but not used in parse-events.y or in the generated parse-events.c.
--- tools/perf/util/parse-events.y | 1 - 1 file changed, 1 deletion(-)
tools/perf/util/parse-events.y +0 -1
@@ -626,7 +626,6 @@ PE_TERM PE_NAME array '=' PE_NAME { struct parse_events_term *term; - int i; ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, $1, $4, &@1, &@4));
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 18/25 perf parse-events: Remove unused variable: error
In reply to Arnaldo Carvalho de MeloFrom: Luke Mujica <[email protected]>
Remove the 'error' variable because it is declared but not used in parse-events.y or in the generated parse-events.c.
--- tools/perf/util/parse-events.y | 1 - 1 file changed, 1 deletion(-)
tools/perf/util/parse-events.y +0 -1
@@ -480,7 +480,6 @@ event_bpf_file: PE_BPF_OBJECT opt_event_config { struct parse_events_state *parse_state = _parse_state; - struct parse_events_error *error = parse_state->error; struct list_head *list; ALLOC_LIST(list);
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 19/25 perf cs-etm: Fix potential NULL pointer dereference found by the smatch tool
In reply to Arnaldo Carvalho de MeloFrom: Leo Yan <[email protected]>
Based on the following report from Smatch, fix the potential NULL pointer dereference check.
tools/perf/util/cs-etm.c:2545 cs_etm__process_auxtrace_info() error: we previously assumed 'session->itrace_synth_opts' could be null (see line 2541)
tools/perf/util/cs-etm.c
2541 if (session->itrace_synth_opts && session->itrace_synth_opts->set) {
2542 etm->synth_opts = *session->itrace_synth_opts;
2543 } else {
2544 itrace_synth_opts__set_default(&etm->synth_opts,
2545 session->itrace_synth_opts->default_no_sample);
^^^^^^^^^^^^^^^^^^^^^^^^^^
2546 etm->synth_opts.callchain = false;
2547 }'session->itrace_synth_opts' is impossible to be a NULL pointer in cs_etm__process_auxtrace_info(), thus this patch removes the NULL test for 'session->itrace_synth_opts'.
--- tools/perf/util/cs-etm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/cs-etm.c +1 -1
@@ -2538,7 +2538,7 @@ int cs_etm__process_auxtrace_info(union perf_event *event,return 0 ; } -if (session->itrace_synth_opts && session->itrace_synth_opts->set) { +if (session->itrace_synth_opts->set) { etm->synth_opts = *session->itrace_synth_opts; }else { itrace_synth_opts__set_default(&etm->synth_opts,
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 20/25 perf hists browser: Fix potential NULL pointer dereference found by the smatch tool
In reply to Arnaldo Carvalho de MeloFrom: Leo Yan <[email protected]>
Based on the following report from Smatch, fix the potential NULL pointer dereference check.
tools/perf/ui/browsers/hists.c:641 hist_browser__run() error: we previously assumed 'hbt' could be null (see line 625)
tools/perf/ui/browsers/hists.c:3088 perf_evsel__hists_browse() error: we previously assumed 'browser->he_selection' could be null (see line 2902)
tools/perf/ui/browsers/hists.c:3272 perf_evsel_menu__run() error: we previously assumed 'hbt' could be null (see line 3260)
This patch firstly validating the pointers before access them, so can fix potential NULL pointer dereference.
--- tools/perf/ui/browsers/hists.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
tools/perf/ui/browsers/hists.c +11 -4
@@ -639,7 +639,11 @@ int hist_browser__run(struct hist_browser *browser, const char *help,switch (key) {case K_TIMER : {u64 nr_entries; - hbt->timer (hbt->arg); + +WARN_ON_ONCE (!hbt); + +if (hbt) + hbt->timer (hbt->arg);if (hist_browser__has_filter (browser) || symbol_conf.report_hierarchy)
@@ -2821,7 +2825,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, {struct hists *hists =evsel__hists (evsel);struct hist_browser *browser =perf_evsel_browser__new (evsel, hbt, env, annotation_opts); -struct branch_info *bi; +struct branch_info *bi =NULL ;#define MAX_OPTIONS 16char *options[MAX_OPTIONS ];struct popup_action actions[MAX_OPTIONS ];
@@ -3087,7 +3091,9 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, goto skip_annotation;if (sort__mode ==SORT_MODE__BRANCH ) { - bi = browser->he_selection->branch_info; + +if (browser->he_selection) + bi = browser->he_selection->branch_info;if (bi ==NULL ) goto skip_annotation;
@@ -3271,7 +3277,8 @@ static int perf_evsel_menu__run(struct perf_evsel_menu *menu,switch (key) {case K_TIMER : - hbt->timer (hbt->arg); +if (hbt) + hbt->timer (hbt->arg); if (!menu->lost_events_warned && menu->lost_events &&
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 21/25 perf scripts python: export-to-postgresql.py: Fix DROP VIEW power_events_view
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
PostgreSQL can error if power_events_view is not dropped before its dependent tables e.g.
Exception: Query failed: ERROR: cannot drop table mwait because other objects depend on it
DETAIL: view power_events_view depends on table mwait
--- tools/perf/scripts/python/export-to-postgresql.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/scripts/python/export-to-postgresql.py +1 -1
@@ -898,11 +898,11 @@ def trace_end(): if is_table_empty("ptwrite"): drop("ptwrite") if is_table_empty("mwait") and is_table_empty("pwre") and is_table_empty("exstop") and is_table_empty("pwrx"): + do_query(query, 'DROP VIEW power_events_view'); drop("mwait") drop("pwre") drop("exstop") drop("pwrx") - do_query(query, 'DROP VIEW power_events_view'); if is_table_empty("cbr"): drop("cbr")
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 22/25 perf scripts python: export-to-sqlite.py: Fix DROP VIEW power_events_view
In reply to Arnaldo Carvalho de MeloFrom: Adrian Hunter <[email protected]>
Drop power_events_view before its dependent tables.
SQLite does not seem to mind but the fix was needed for PostgreSQL (export-to-postgresql.py script), so do the same fix for the SQLite. It is more logical and keeps the 2 scripts following the same approach.
--- tools/perf/scripts/python/export-to-sqlite.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/scripts/python/export-to-sqlite.py +1 -1
@@ -608,11 +608,11 @@ def trace_end(): if is_table_empty("ptwrite"): drop("ptwrite") if is_table_empty("mwait") and is_table_empty("pwre") and is_table_empty("exstop") and is_table_empty("pwrx"): + do_query(query, 'DROP VIEW power_events_view'); drop("mwait") drop("pwre") drop("exstop") drop("pwrx") - do_query(query, 'DROP VIEW power_events_view'); if is_table_empty("cbr"): drop("cbr")
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 23/25 perf script: Assume native_arch for pipe mode
In reply to Arnaldo Carvalho de MeloFrom: Song Liu <[email protected]>
In pipe mode, session->header.env.arch is not populated until the events are processed. Therefore, the following command crashes:
perf record -o - | perf script
(gdb) bt
It fails when we try to compare env.arch against uts.machine:
if (!strcmp(uts.machine, session->header.env.arch) ||
(!strcmp(uts.machine, "x86_64") &&
!strcmp(session->header.env.arch, "i386")))
native_arch = true;In pipe mode, it is tricky to find env.arch at this stage. To keep it simple, let's just assume native_arch is always true for pipe mode.
--- tools/perf/builtin-script.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/builtin-script.c +2 -1
@@ -3752,7 +3752,8 @@ int cmd_script(int argc, const char **argv) goto out_delete;uname (&uts); -if (!strcmp (uts.machine, session->header.env.arch) || +if (data.is_pipe ||/* assume pipe_mode indicates native_arch */ + !strcmp (uts.machine, session->header.env.arch) || (!strcmp (uts.machine,"x86_64" ) && !strcmp (session->header.env.arch,"i386" ))) native_arch = true;
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 24/25 perf intel-bts: Fix potential NULL pointer dereference found by the smatch tool
In reply to Arnaldo Carvalho de MeloFrom: Leo Yan <[email protected]>
Based on the following report from Smatch, fix the potential NULL pointer dereference check.
tools/perf/util/intel-bts.c:898 intel_bts_process_auxtrace_info() error: we previously assumed 'session->itrace_synth_opts' could be null (see line 894)
tools/perf/util/intel-bts.c:899 intel_bts_process_auxtrace_info() warn: variable dereferenced before check 'session->itrace_synth_opts' (see line 898)
tools/perf/util/intel-bts.c
894 if (session->itrace_synth_opts && session->itrace_synth_opts->set) {
895 bts->synth_opts = *session->itrace_synth_opts;
896 } else {
897 itrace_synth_opts__set_default(&bts->synth_opts,
898 session->itrace_synth_opts->default_no_sample);
^^^^^^^^^^^^^^^^^^^^^^^^^^
899 if (session->itrace_synth_opts)
^^^^^^^^^^^^^^^^^^^^^^^^^^
900 bts->synth_opts.thread_stack =
901 session->itrace_synth_opts->thread_stack;
902 }'session->itrace_synth_opts' is impossible to be a NULL pointer in intel_bts_process_auxtrace_info(), thus this patch removes the NULL test for 'session->itrace_synth_opts'.
--- tools/perf/util/intel-bts.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
tools/perf/util/intel-bts.c +2 -3
@@ -891,13 +891,12 @@ int intel_bts_process_auxtrace_info(union perf_event *event,if (dump_trace)return 0 ; -if (session->itrace_synth_opts && session->itrace_synth_opts->set) { +if (session->itrace_synth_opts->set) { bts->synth_opts = *session->itrace_synth_opts; }else {itrace_synth_opts__set_default (&bts->synth_opts, session->itrace_synth_opts->default_no_sample); -if (session->itrace_synth_opts) - bts->synth_opts.thread_stack = + bts->synth_opts.thread_stack = session->itrace_synth_opts->thread_stack; }
Signature · 1 line
2.21.0
Arnaldo Carvalho de Melo
maintainerPATCH 25/25 perf intel-pt: Fix potential NULL pointer dereference found by the smatch tool
In reply to Arnaldo Carvalho de MeloFrom: Leo Yan <[email protected]>
Based on the following report from Smatch, fix the potential NULL pointer dereference check.
tools/perf/util/intel-pt.c:3200 intel_pt_process_auxtrace_info() error: we previously assumed 'session->itrace_synth_opts' could be null (see line 3196)
tools/perf/util/intel-pt.c:3206 intel_pt_process_auxtrace_info() warn: variable dereferenced before check 'session->itrace_synth_opts' (see line 3200)
tools/perf/util/intel-pt.c
3196 if (session->itrace_synth_opts && session->itrace_synth_opts->set) {
3197 pt->synth_opts = *session->itrace_synth_opts;
3198 } else {
3199 itrace_synth_opts__set_default(&pt->synth_opts,
3200 session->itrace_synth_opts->default_no_sample);
^^^^^^^^^^^^^^^^^^^^^^^^^^
3201 if (!session->itrace_synth_opts->default_no_sample &&
3202 !session->itrace_synth_opts->inject) {
3203 pt->synth_opts.branches = false;
3204 pt->synth_opts.callchain = true;
3205 }
3206 if (session->itrace_synth_opts)
^^^^^^^^^^^^^^^^^^^^^^^^^^
3207 pt->synth_opts.thread_stack =
3208 session->itrace_synth_opts->thread_stack;
3209 }'session->itrace_synth_opts' is impossible to be a NULL pointer in intel_pt_process_auxtrace_info(), thus this patch removes the NULL test for 'session->itrace_synth_opts'.
--- tools/perf/util/intel-pt.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
tools/perf/util/intel-pt.c +5 -8
@@ -3210,7 +3210,7 @@ int intel_pt_process_auxtrace_info(union perf_event *event, goto err_delete_thread; } -if (session->itrace_synth_opts && session->itrace_synth_opts->set) { +if (session->itrace_synth_opts->set) { pt->synth_opts = *session->itrace_synth_opts; }else { itrace_synth_opts__set_default(&pt->synth_opts,
@@ -3220,8 +3220,7 @@ int intel_pt_process_auxtrace_info(union perf_event *event, pt->synth_opts.branches = false; pt->synth_opts.callchain = true; } -if (session->itrace_synth_opts) - pt->synth_opts.thread_stack = + pt->synth_opts.thread_stack = session->itrace_synth_opts->thread_stack; }
@@ -3241,11 +3240,9 @@ int intel_pt_process_auxtrace_info(union perf_event *event, pt->cbr2khz = tsc_freq / pt->max_non_turbo_ratio /1000 ; } -if (session->itrace_synth_opts) { - err =intel_pt_setup_time_ranges (pt, session->itrace_synth_opts); -if (err) - goto err_delete_thread; - } + err =intel_pt_setup_time_ranges (pt, session->itrace_synth_opts); +if (err) + goto err_delete_thread;if (pt->synth_opts.calls) pt->branches_filter |= PERF_IP_FLAG_CALL | PERF_IP_FLAG_ASYNC |
Signature · 1 line
2.21.0
Quoted 256 lines · Arnaldo Carvalho de Melo
Hi Ingo,
Please consider pulling,
Best regards,
- Arnaldo
Test results at the end of this message, as usual.
The following changes since commit
d1d59b817939821bee149e870ce7723f61ffb512:Merge tag 'perf-urgent-for-mingo-5.3-20190708-2' of
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linuxinto perf/core (2019-07-09 13:22:03 +0200)are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.gittags/perf-core-for-mingo-5.3-20190709for you to fetch changes up to
323fd749821daab0f327ec86d707c4542963cdb0:perf intel-pt: Fix potential NULL pointer dereference found by the smatch tool (2019-07-09 10:13:28 -0300)
----------------------------------------------------------------
perf/core improvements and fixes:Intel PT:
Adrian Hunter:
- Fix DROP VIEW
power_events_viewin the postgresql and sqlite export-db python scripts.perf script:
Song Liu:
- Assume
native_archfor pipe mode, fixing a segfault.perf inject:
Arnaldo Carvalho de Melo:
- The
tool->read()call may pass a NULL evsel, handle it.core:
Arnaldo Carvalho de Melo:
- Move
zalloc/zfree.ctotools/lib, further eroding tools/perf/util.[ch]- Use
zfree()where applicable instead of open coded equivalent.- Add
stdlib.hand some other headers to places where its needed and were getting viautil.h, that doesn't need that anymore.- Use
list_del_init()more thoroughly.Miscellaneous:
Leo Yan:
- Fix use after free and potential NULL pointer derefs detected by the smatch tool in various places.
Luke Mujica:
- Remove a couple unused variables in the parse-events code.
Numfor Mbiziwo-Tiapo:
- Initialize variable to suppress memory sanitizer warning in the mmap-thread-lookup 'perf test' entry.
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>----------------------------------------------------------------
Adrian Hunter (2):
perf scripts python:export-to-postgresql.py: Fix DROP VIEWpower_events_viewperf scripts python:export-to-sqlite.py: Fix DROP VIEWpower_events_viewArnaldo Carvalho de Melo (9):
perf inject: Thetool->read()call may pass a NULL evsel, handle it perf evsel:perf_evsel__name(NULL)is valid, no need to check evsel perf tools: Add missing headers, mostlystdlib.h
perf namespaces: Move the conditionalsetns()prototype tonamespaces.hperf tools: Moveget_current_dir_name()cond prototype out ofutil.htools lib: Adopt zalloc()/zfree() fromtools/perf
perf tools: Usezfree()where applicable
perf tools: Uselist_del_init()more thorougly
perf metricgroup: Add missinglist_del_init()when flushing egroups listLeo Yan (10):
perf stat: Fix use-after-freed pointer detected by the smatch tool perf top: Fix potential NULL pointer dereference detected by the smatch tool perf annotate: Fix dereferencing freed memory found by the smatch tool perf trace: Fix potential NULL pointer dereference found by the smatch tool perf map: Fix potential NULL pointer dereference found by smatch tool perf session: Fix potential NULL pointer dereference found by the smatch tool perf cs-etm: Fix potential NULL pointer dereference found by the smatch tool perf hists browser: Fix potential NULL pointer dereference found by the smatch tool perf intel-bts: Fix potential NULL pointer dereference found by the smatch tool perf intel-pt: Fix potential NULL pointer dereference found by the smatch toolLuke Mujica (2):
perf parse-events: Remove unused variable 'i' perf parse-events: Remove unused variable: errorNumfor Mbiziwo-Tiapo (1):
perf test mmap-thread-lookup: Initialize variable to suppress memory sanitizer warningSong Liu (1):
perf script: Assumenative_archfor pipe modetools/include/linux/zalloc.h | 12 +++++ tools/lib/zalloc.c | 15 ++++++ tools/perf/MANIFEST | 1 + tools/perf/arch/arm/annotate/instructions.c | 1 + tools/perf/arch/arm/util/auxtrace.c | 1 + tools/perf/arch/arm/util/cs-etm.c | 1 + tools/perf/arch/arm64/util/arm-spe.c | 1 + tools/perf/arch/common.c | 3 +- tools/perf/arch/powerpc/util/perf_regs.c | 4 +- tools/perf/arch/s390/util/auxtrace.c | 1 + tools/perf/arch/s390/util/header.c | 3 +- tools/perf/arch/x86/util/event.c | 2 +- tools/perf/arch/x86/util/intel-bts.c | 2 +- tools/perf/arch/x86/util/intel-pt.c | 2 +- tools/perf/arch/x86/util/perf_regs.c | 2 +- tools/perf/bench/futex-hash.c | 3 +- tools/perf/bench/futex-lock-pi.c | 3 +- tools/perf/bench/mem-functions.c | 2 +- tools/perf/bench/numa.c | 2 +- tools/perf/builtin-annotate.c | 2 +- tools/perf/builtin-bench.c | 2 +- tools/perf/builtin-c2c.c | 2 +- tools/perf/builtin-config.c | 1 + tools/perf/builtin-diff.c | 2 +- tools/perf/builtin-ftrace.c | 2 +- tools/perf/builtin-help.c | 2 + tools/perf/builtin-inject.c | 2 +- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-kvm.c | 2 +- tools/perf/builtin-lock.c | 10 ++-- tools/perf/builtin-probe.c | 2 +- tools/perf/builtin-record.c | 4 +- tools/perf/builtin-report.c | 4 +- tools/perf/builtin-sched.c | 2 +- tools/perf/builtin-script.c | 5 +- tools/perf/builtin-stat.c | 8 ++-- tools/perf/builtin-timechart.c | 4 +- tools/perf/builtin-top.c | 8 +++- tools/perf/builtin-trace.c | 7 +-- tools/perf/perf.c | 2 +- tools/perf/pmu-events/jevents.c | 2 +- tools/perf/scripts/python/export-to-postgresql.py | 2 +- tools/perf/scripts/python/export-to-sqlite.py | 2 +- tools/perf/tests/dwarf-unwind.c | 5 +- tools/perf/tests/expr.c | 3 +- tools/perf/tests/llvm.c | 1 + tools/perf/tests/mem2node.c | 3 +- tools/perf/tests/mmap-thread-lookup.c | 2 +- tools/perf/tests/sample-parsing.c | 1 + tools/perf/tests/switch-tracking.c | 3 +- tools/perf/tests/thread-map.c | 3 +- tools/perf/tests/vmlinux-kallsyms.c | 1 + tools/perf/ui/browser.c | 2 +- tools/perf/ui/browser.h | 1 + tools/perf/ui/browsers/annotate.c | 2 +- tools/perf/ui/browsers/hists.c | 17 +++++-- tools/perf/ui/browsers/map.c | 1 + tools/perf/ui/browsers/res_sample.c | 6 +-- tools/perf/ui/browsers/scripts.c | 4 +- tools/perf/ui/gtk/annotate.c | 2 +- tools/perf/ui/gtk/util.c | 3 +- tools/perf/ui/stdio/hist.c | 2 +- tools/perf/ui/tui/setup.c | 1 + tools/perf/ui/tui/util.c | 2 +- tools/perf/util/Build | 5 ++ tools/perf/util/annotate.c | 13 ++--- tools/perf/util/arm-spe.c | 2 +- tools/perf/util/auxtrace.c | 11 ++--- tools/perf/util/bpf-loader.c | 3 +- tools/perf/util/build-id.c | 1 + tools/perf/util/call-path.c | 5 +- tools/perf/util/callchain.c | 12 ++--- tools/perf/util/cgroup.c | 4 +- tools/perf/util/comm.c | 2 +- tools/perf/util/config.c | 3 +- tools/perf/util/counts.c | 2 +- tools/perf/util/cpumap.c | 2 +- tools/perf/util/cputopo.c | 5 +- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 1 + tools/perf/util/cs-etm.c | 8 ++-- tools/perf/util/data-convert-bt.c | 4 +- tools/perf/util/data.c | 3 +- tools/perf/util/db-export.c | 7 +-- tools/perf/util/debug.c | 1 + tools/perf/util/demangle-java.c | 3 +- tools/perf/util/dso.c | 5 +- tools/perf/util/dwarf-aux.c | 2 +- tools/perf/util/env.c | 11 +++-- tools/perf/util/event.c | 3 +- tools/perf/util/evlist.c | 2 +- tools/perf/util/evsel.c | 4 +- tools/perf/util/get_current_dir_name.c | 6 +-- tools/perf/util/get_current_dir_name.h | 8 ++++ tools/perf/util/header.c | 8 ++-- tools/perf/util/help-unknown-cmd.c | 2 + tools/perf/util/hist.c | 20 ++++---- tools/perf/util/intel-bts.c | 7 ++- .../perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 +- tools/perf/util/intel-pt.c | 15 +++--- tools/perf/util/jitdump.c | 7 ++- tools/perf/util/llvm-utils.c | 4 +- tools/perf/util/machine.c | 6 +-- tools/perf/util/map.c | 9 ++-- tools/perf/util/mem2node.c | 2 +- tools/perf/util/metricgroup.c | 10 ++-- tools/perf/util/mmap.c | 1 + tools/perf/util/namespaces.c | 3 +- tools/perf/util/namespaces.h | 4 ++ tools/perf/util/ordered-events.c | 6 +-- tools/perf/util/parse-branch-options.c | 2 +- tools/perf/util/parse-events.c | 3 +- tools/perf/util/parse-events.y | 2 - tools/perf/util/parse-regs-options.c | 8 +++- tools/perf/util/pmu.c | 4 +- tools/perf/util/probe-event.c | 55 ++++++++++------------ tools/perf/util/probe-file.c | 2 +- tools/perf/util/probe-finder.c | 2 +- tools/perf/util/pstack.c | 2 +- tools/perf/util/python-ext-sources | 1 + tools/perf/util/s390-cpumsf.c | 11 ++--- tools/perf/util/session.c | 7 ++- tools/perf/util/setns.c | 4 +- tools/perf/util/srccode.c | 11 +++-- tools/perf/util/srcline.c | 2 +- tools/perf/util/stat-shadow.c | 3 +- tools/perf/util/stat.c | 3 +- tools/perf/util/strbuf.c | 3 +- tools/perf/util/strfilter.c | 3 +- tools/perf/util/strlist.c | 2 +- tools/perf/util/svghelper.c | 2 +- tools/perf/util/symbol-elf.c | 18 +++---- tools/perf/util/symbol-minimal.c | 3 +- tools/perf/util/symbol.c | 1 + tools/perf/util/syscalltbl.c | 2 +- tools/perf/util/target.c | 2 +- tools/perf/util/thread-stack.c | 3 +- tools/perf/util/thread.c | 6 +-- tools/perf/util/thread_map.c | 4 +- tools/perf/util/trace-event-info.c | 1 + tools/perf/util/trace-event-scripting.c | 2 +- tools/perf/util/unwind-libdw.c | 1 + tools/perf/util/unwind-libunwind-local.c | 3 +- tools/perf/util/usage.c | 3 ++
Quoted 8 lines
tools/perf/util/util.h | 17 ------- tools/perf/util/values.c | 2 +- tools/perf/util/vdso.c | 1 + tools/perf/util/xyarray.c | 2 +- 147 files changed, 375 insertions(+), 279 deletions(-) create mode 100644 tools/include/linux/zalloc.h create mode 100644 tools/lib/zalloc.c create mode 100644 tools/perf/util/get_current_dir_name.h
Pulled, thanks a lot Arnaldo!
Ingo