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

Merge tag 'perf-core-for-mingo-5.3-20190709' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent

Pull 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.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>

+375 -279
+12
tools/include/linux/zalloc.h
··· 1 + // SPDX-License-Identifier: LGPL-2.1 2 + #ifndef __TOOLS_LINUX_ZALLOC_H 3 + #define __TOOLS_LINUX_ZALLOC_H 4 + 5 + #include <stddef.h> 6 + 7 + void *zalloc(size_t size); 8 + void __zfree(void **ptr); 9 + 10 + #define zfree(ptr) __zfree((void **)(ptr)) 11 + 12 + #endif // __TOOLS_LINUX_ZALLOC_H
+15
tools/lib/zalloc.c
··· 1 + // SPDX-License-Identifier: LGPL-2.1 2 + 3 + #include <stdlib.h> 4 + #include <linux/zalloc.h> 5 + 6 + void *zalloc(size_t size) 7 + { 8 + return calloc(1, size); 9 + } 10 + 11 + void __zfree(void **ptr) 12 + { 13 + free(*ptr); 14 + *ptr = NULL; 15 + }
+1
tools/perf/MANIFEST
··· 18 18 tools/lib/bitmap.c 19 19 tools/lib/str_error_r.c 20 20 tools/lib/vsprintf.c 21 + tools/lib/zalloc.c
+1
tools/perf/arch/arm/annotate/instructions.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include <linux/compiler.h> 3 + #include <linux/zalloc.h> 3 4 #include <sys/types.h> 4 5 #include <regex.h> 5 6
+1
tools/perf/arch/arm/util/auxtrace.c
··· 6 6 7 7 #include <stdbool.h> 8 8 #include <linux/coresight-pmu.h> 9 + #include <linux/zalloc.h> 9 10 10 11 #include "../../util/auxtrace.h" 11 12 #include "../../util/evlist.h"
+1
tools/perf/arch/arm/util/cs-etm.c
··· 12 12 #include <linux/kernel.h> 13 13 #include <linux/log2.h> 14 14 #include <linux/types.h> 15 + #include <linux/zalloc.h> 15 16 16 17 #include "cs-etm.h" 17 18 #include "../../perf.h"
+1
tools/perf/arch/arm64/util/arm-spe.c
··· 8 8 #include <linux/types.h> 9 9 #include <linux/bitops.h> 10 10 #include <linux/log2.h> 11 + #include <linux/zalloc.h> 11 12 #include <time.h> 12 13 13 14 #include "../../util/cpumap.h"
+2 -1
tools/perf/arch/common.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include <stdio.h> 3 + #include <stdlib.h> 3 4 #include "common.h" 4 5 #include "../util/env.h" 5 - #include "../util/util.h" 6 6 #include "../util/debug.h" 7 + #include <linux/zalloc.h> 7 8 8 9 const char *const arc_triplets[] = { 9 10 "arc-linux-",
+3 -1
tools/perf/arch/powerpc/util/perf_regs.c
··· 2 2 #include <errno.h> 3 3 #include <string.h> 4 4 #include <regex.h> 5 + #include <linux/zalloc.h> 5 6 6 7 #include "../../perf.h" 7 - #include "../../util/util.h" 8 8 #include "../../util/perf_regs.h" 9 9 #include "../../util/debug.h" 10 + 11 + #include <linux/kernel.h> 10 12 11 13 const struct sample_reg sample_reg_masks[] = { 12 14 SMPL_REG(r0, PERF_REG_POWERPC_R0),
+1
tools/perf/arch/s390/util/auxtrace.c
··· 3 3 #include <linux/types.h> 4 4 #include <linux/bitops.h> 5 5 #include <linux/log2.h> 6 + #include <linux/zalloc.h> 6 7 7 8 #include "../../util/evlist.h" 8 9 #include "../../util/auxtrace.h"
+2 -1
tools/perf/arch/s390/util/header.c
··· 12 12 #include <stdio.h> 13 13 #include <string.h> 14 14 #include <linux/ctype.h> 15 + #include <linux/kernel.h> 16 + #include <linux/zalloc.h> 15 17 16 18 #include "../../util/header.h" 17 - #include "../../util/util.h" 18 19 19 20 #define SYSINFO_MANU "Manufacturer:" 20 21 #define SYSINFO_TYPE "Type:"
+1 -1
tools/perf/arch/x86/util/event.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include <linux/types.h> 3 3 #include <linux/string.h> 4 + #include <linux/zalloc.h> 4 5 5 6 #include "../../util/machine.h" 6 7 #include "../../util/tool.h" 7 8 #include "../../util/map.h" 8 - #include "../../util/util.h" 9 9 #include "../../util/debug.h" 10 10 11 11 #if defined(__x86_64__)
+1 -1
tools/perf/arch/x86/util/intel-bts.c
··· 9 9 #include <linux/types.h> 10 10 #include <linux/bitops.h> 11 11 #include <linux/log2.h> 12 + #include <linux/zalloc.h> 12 13 13 14 #include "../../util/cpumap.h" 14 15 #include "../../util/evsel.h" 15 16 #include "../../util/evlist.h" 16 17 #include "../../util/session.h" 17 - #include "../../util/util.h" 18 18 #include "../../util/pmu.h" 19 19 #include "../../util/debug.h" 20 20 #include "../../util/tsc.h"
+1 -1
tools/perf/arch/x86/util/intel-pt.c
··· 10 10 #include <linux/types.h> 11 11 #include <linux/bitops.h> 12 12 #include <linux/log2.h> 13 + #include <linux/zalloc.h> 13 14 #include <cpuid.h> 14 15 15 16 #include "../../perf.h" ··· 26 25 #include "../../util/auxtrace.h" 27 26 #include "../../util/tsc.h" 28 27 #include "../../util/intel-pt.h" 29 - #include "../../util/util.h" 30 28 31 29 #define KiB(x) ((x) * 1024) 32 30 #define MiB(x) ((x) * 1024 * 1024)
+1 -1
tools/perf/arch/x86/util/perf_regs.c
··· 2 2 #include <errno.h> 3 3 #include <string.h> 4 4 #include <regex.h> 5 + #include <linux/zalloc.h> 5 6 6 7 #include "../../perf.h" 7 - #include "../../util/util.h" 8 8 #include "../../util/perf_regs.h" 9 9 #include "../../util/debug.h" 10 10
+2 -1
tools/perf/bench/futex-hash.c
··· 18 18 #include <stdlib.h> 19 19 #include <linux/compiler.h> 20 20 #include <linux/kernel.h> 21 + #include <linux/zalloc.h> 21 22 #include <sys/time.h> 22 23 23 24 #include "../util/stat.h" ··· 215 214 &worker[i].futex[nfutexes-1], t); 216 215 } 217 216 218 - free(worker[i].futex); 217 + zfree(&worker[i].futex); 219 218 } 220 219 221 220 print_summary();
+2 -1
tools/perf/bench/futex-lock-pi.c
··· 12 12 #include <subcmd/parse-options.h> 13 13 #include <linux/compiler.h> 14 14 #include <linux/kernel.h> 15 + #include <linux/zalloc.h> 15 16 #include <errno.h> 16 17 #include "bench.h" 17 18 #include "futex.h" ··· 218 217 worker[i].tid, worker[i].futex, t); 219 218 220 219 if (multi) 221 - free(worker[i].futex); 220 + zfree(&worker[i].futex); 222 221 } 223 222 224 223 print_summary();
+1 -1
tools/perf/bench/mem-functions.c
··· 9 9 10 10 #include "debug.h" 11 11 #include "../perf.h" 12 - #include "../util/util.h" 13 12 #include <subcmd/parse-options.h> 14 13 #include "../util/header.h" 15 14 #include "../util/cloexec.h" ··· 23 24 #include <sys/time.h> 24 25 #include <errno.h> 25 26 #include <linux/time64.h> 27 + #include <linux/zalloc.h> 26 28 27 29 #define K 1024 28 30
+1 -1
tools/perf/bench/numa.c
··· 11 11 12 12 #include "../perf.h" 13 13 #include "../builtin.h" 14 - #include "../util/util.h" 15 14 #include <subcmd/parse-options.h> 16 15 #include "../util/cloexec.h" 17 16 ··· 34 35 #include <linux/kernel.h> 35 36 #include <linux/time64.h> 36 37 #include <linux/numa.h> 38 + #include <linux/zalloc.h> 37 39 38 40 #include <numa.h> 39 41 #include <numaif.h>
+1 -1
tools/perf/builtin-annotate.c
··· 8 8 */ 9 9 #include "builtin.h" 10 10 11 - #include "util/util.h" 12 11 #include "util/color.h" 13 12 #include <linux/list.h> 14 13 #include "util/cache.h" 15 14 #include <linux/rbtree.h> 15 + #include <linux/zalloc.h> 16 16 #include "util/symbol.h" 17 17 18 18 #include "perf.h"
+1 -1
tools/perf/builtin-bench.c
··· 17 17 * epoll ... Event poll performance 18 18 */ 19 19 #include "perf.h" 20 - #include "util/util.h" 21 20 #include <subcmd/parse-options.h> 22 21 #include "builtin.h" 23 22 #include "bench/bench.h" ··· 25 26 #include <stdlib.h> 26 27 #include <string.h> 27 28 #include <sys/prctl.h> 29 + #include <linux/zalloc.h> 28 30 29 31 typedef int (*bench_fn_t)(int argc, const char **argv); 30 32
+1 -1
tools/perf/builtin-c2c.c
··· 15 15 #include <linux/compiler.h> 16 16 #include <linux/kernel.h> 17 17 #include <linux/stringify.h> 18 + #include <linux/zalloc.h> 18 19 #include <asm/bug.h> 19 20 #include <sys/param.h> 20 - #include "util.h" 21 21 #include "debug.h" 22 22 #include "builtin.h" 23 23 #include <subcmd/parse-options.h>
+1
tools/perf/builtin-config.c
··· 15 15 #include "util/debug.h" 16 16 #include "util/config.h" 17 17 #include <linux/string.h> 18 + #include <stdlib.h> 18 19 19 20 static bool use_system_config, use_user_config; 20 21
+1 -1
tools/perf/builtin-diff.c
··· 16 16 #include "util/tool.h" 17 17 #include "util/sort.h" 18 18 #include "util/symbol.h" 19 - #include "util/util.h" 20 19 #include "util/data.h" 21 20 #include "util/config.h" 22 21 #include "util/time-utils.h" 23 22 #include "util/annotate.h" 24 23 #include "util/map.h" 24 + #include <linux/zalloc.h> 25 25 26 26 #include <errno.h> 27 27 #include <inttypes.h>
+1 -1
tools/perf/builtin-ftrace.c
··· 431 431 struct filter_entry *pos, *tmp; 432 432 433 433 list_for_each_entry_safe(pos, tmp, head, list) { 434 - list_del(&pos->list); 434 + list_del_init(&pos->list); 435 435 free(pos); 436 436 } 437 437 }
+2
tools/perf/builtin-help.c
··· 14 14 #include <subcmd/help.h> 15 15 #include "util/debug.h" 16 16 #include <linux/kernel.h> 17 + #include <linux/zalloc.h> 17 18 #include <errno.h> 18 19 #include <stdio.h> 20 + #include <stdlib.h> 19 21 #include <sys/types.h> 20 22 #include <sys/stat.h> 21 23 #include <unistd.h>
+1 -1
tools/perf/builtin-inject.c
··· 224 224 struct perf_evsel *evsel, 225 225 struct machine *machine) 226 226 { 227 - if (evsel->handler) { 227 + if (evsel && evsel->handler) { 228 228 inject_handler f = evsel->handler; 229 229 return f(tool, event, sample, evsel, machine); 230 230 }
+1 -1
tools/perf/builtin-kmem.c
··· 4 4 5 5 #include "util/evlist.h" 6 6 #include "util/evsel.h" 7 - #include "util/util.h" 8 7 #include "util/config.h" 9 8 #include "util/map.h" 10 9 #include "util/symbol.h" ··· 25 26 #include <linux/kernel.h> 26 27 #include <linux/rbtree.h> 27 28 #include <linux/string.h> 29 + #include <linux/zalloc.h> 28 30 #include <errno.h> 29 31 #include <inttypes.h> 30 32 #include <locale.h>
+1 -1
tools/perf/builtin-kvm.c
··· 5 5 #include "util/evsel.h" 6 6 #include "util/evlist.h" 7 7 #include "util/term.h" 8 - #include "util/util.h" 9 8 #include "util/cache.h" 10 9 #include "util/symbol.h" 11 10 #include "util/thread.h" ··· 31 32 32 33 #include <linux/kernel.h> 33 34 #include <linux/time64.h> 35 + #include <linux/zalloc.h> 34 36 #include <errno.h> 35 37 #include <inttypes.h> 36 38 #include <poll.h>
+5 -5
tools/perf/builtin-lock.c
··· 6 6 7 7 #include "util/evlist.h" 8 8 #include "util/evsel.h" 9 - #include "util/util.h" 10 9 #include "util/cache.h" 11 10 #include "util/symbol.h" 12 11 #include "util/thread.h" ··· 29 30 #include <linux/list.h> 30 31 #include <linux/hash.h> 31 32 #include <linux/kernel.h> 33 + #include <linux/zalloc.h> 32 34 33 35 static struct perf_session *session; 34 36 ··· 454 454 /* broken lock sequence, discard it */ 455 455 ls->discard = 1; 456 456 bad_hist[BROKEN_ACQUIRE]++; 457 - list_del(&seq->list); 457 + list_del_init(&seq->list); 458 458 free(seq); 459 459 goto end; 460 460 default: ··· 515 515 /* broken lock sequence, discard it */ 516 516 ls->discard = 1; 517 517 bad_hist[BROKEN_ACQUIRED]++; 518 - list_del(&seq->list); 518 + list_del_init(&seq->list); 519 519 free(seq); 520 520 goto end; 521 521 default: ··· 570 570 /* broken lock sequence, discard it */ 571 571 ls->discard = 1; 572 572 bad_hist[BROKEN_CONTENDED]++; 573 - list_del(&seq->list); 573 + list_del_init(&seq->list); 574 574 free(seq); 575 575 goto end; 576 576 default: ··· 639 639 640 640 ls->nr_release++; 641 641 free_seq: 642 - list_del(&seq->list); 642 + list_del_init(&seq->list); 643 643 free(seq); 644 644 end: 645 645 return 0;
+1 -1
tools/perf/builtin-probe.c
··· 19 19 #include "perf.h" 20 20 #include "builtin.h" 21 21 #include "namespaces.h" 22 - #include "util/util.h" 23 22 #include "util/strlist.h" 24 23 #include "util/strfilter.h" 25 24 #include "util/symbol.h" ··· 27 28 #include "util/probe-finder.h" 28 29 #include "util/probe-event.h" 29 30 #include "util/probe-file.h" 31 + #include <linux/zalloc.h> 30 32 31 33 #define DEFAULT_VAR_FILTER "!__k???tab_* & !__crc_*" 32 34 #define DEFAULT_FUNC_FILTER "!_*"
+2 -2
tools/perf/builtin-record.c
··· 11 11 #include "perf.h" 12 12 13 13 #include "util/build-id.h" 14 - #include "util/util.h" 15 14 #include <subcmd/parse-options.h> 16 15 #include "util/parse-events.h" 17 16 #include "util/config.h" ··· 53 54 #include <sys/mman.h> 54 55 #include <sys/wait.h> 55 56 #include <linux/time64.h> 57 + #include <linux/zalloc.h> 56 58 57 59 struct switch_output { 58 60 bool enabled; ··· 1110 1110 rec->switch_output.cur_file = n; 1111 1111 if (rec->switch_output.filenames[n]) { 1112 1112 remove(rec->switch_output.filenames[n]); 1113 - free(rec->switch_output.filenames[n]); 1113 + zfree(&rec->switch_output.filenames[n]); 1114 1114 } 1115 1115 rec->switch_output.filenames[n] = new_filename; 1116 1116 } else {
+2 -2
tools/perf/builtin-report.c
··· 8 8 */ 9 9 #include "builtin.h" 10 10 11 - #include "util/util.h" 12 11 #include "util/config.h" 13 12 14 13 #include "util/annotate.h" ··· 15 16 #include <linux/list.h> 16 17 #include <linux/rbtree.h> 17 18 #include <linux/err.h> 19 + #include <linux/zalloc.h> 18 20 #include "util/map.h" 19 21 #include "util/symbol.h" 20 22 #include "util/callchain.h" ··· 298 298 struct report *rep = container_of(tool, struct report, tool); 299 299 300 300 if (rep->show_threads) { 301 - const char *name = evsel ? perf_evsel__name(evsel) : "unknown"; 301 + const char *name = perf_evsel__name(evsel); 302 302 int err = perf_read_values_add_value(&rep->show_threads_values, 303 303 event->read.pid, event->read.tid, 304 304 evsel->idx,
+1 -1
tools/perf/builtin-sched.c
··· 2 2 #include "builtin.h" 3 3 #include "perf.h" 4 4 5 - #include "util/util.h" 6 5 #include "util/evlist.h" 7 6 #include "util/cache.h" 8 7 #include "util/evsel.h" ··· 25 26 26 27 #include <linux/kernel.h> 27 28 #include <linux/log2.h> 29 + #include <linux/zalloc.h> 28 30 #include <sys/prctl.h> 29 31 #include <sys/resource.h> 30 32 #include <inttypes.h>
+3 -2
tools/perf/builtin-script.c
··· 14 14 #include "util/symbol.h" 15 15 #include "util/thread.h" 16 16 #include "util/trace-event.h" 17 - #include "util/util.h" 18 17 #include "util/evlist.h" 19 18 #include "util/evsel.h" 20 19 #include "util/sort.h" ··· 33 34 #include <linux/kernel.h> 34 35 #include <linux/stringify.h> 35 36 #include <linux/time64.h> 37 + #include <linux/zalloc.h> 36 38 #include <sys/utsname.h> 37 39 #include "asm/bug.h" 38 40 #include "util/mem-events.h" ··· 3752 3752 goto out_delete; 3753 3753 3754 3754 uname(&uts); 3755 - if (!strcmp(uts.machine, session->header.env.arch) || 3755 + if (data.is_pipe || /* assume pipe_mode indicates native_arch */ 3756 + !strcmp(uts.machine, session->header.env.arch) || 3756 3757 (!strcmp(uts.machine, "x86_64") && 3757 3758 !strcmp(session->header.env.arch, "i386"))) 3758 3759 native_arch = true;
+4 -4
tools/perf/builtin-stat.c
··· 43 43 #include "perf.h" 44 44 #include "builtin.h" 45 45 #include "util/cgroup.h" 46 - #include "util/util.h" 47 46 #include <subcmd/parse-options.h> 48 47 #include "util/parse-events.h" 49 48 #include "util/pmu.h" ··· 66 67 #include "asm/bug.h" 67 68 68 69 #include <linux/time64.h> 70 + #include <linux/zalloc.h> 69 71 #include <api/fs/fs.h> 70 72 #include <errno.h> 71 73 #include <signal.h> ··· 1349 1349 fprintf(stderr, 1350 1350 "Cannot set up top down events %s: %d\n", 1351 1351 str, err); 1352 - free(str); 1353 1352 parse_events_print_error(&errinfo, str); 1353 + free(str); 1354 1354 return -1; 1355 1355 } 1356 1356 } else { ··· 1586 1586 for (i = 0; i < config->stats_num; i++) 1587 1587 runtime_stat__exit(&config->stats[i]); 1588 1588 1589 - free(config->stats); 1589 + zfree(&config->stats); 1590 1590 } 1591 1591 1592 1592 static const char * const stat_report_usage[] = { ··· 2003 2003 perf_stat__exit_aggr_mode(); 2004 2004 perf_evlist__free_stats(evsel_list); 2005 2005 out: 2006 - free(stat_config.walltime_run); 2006 + zfree(&stat_config.walltime_run); 2007 2007 2008 2008 if (smi_cost && smi_reset) 2009 2009 sysfs__write_int(FREEZE_ON_SMI_PATH, 0);
+1 -3
tools/perf/builtin-timechart.c
··· 13 13 #include <traceevent/event-parse.h> 14 14 15 15 #include "builtin.h" 16 - 17 - #include "util/util.h" 18 - 19 16 #include "util/color.h" 20 17 #include <linux/list.h> 21 18 #include "util/cache.h" ··· 21 24 #include <linux/kernel.h> 22 25 #include <linux/rbtree.h> 23 26 #include <linux/time64.h> 27 + #include <linux/zalloc.h> 24 28 #include "util/symbol.h" 25 29 #include "util/thread.h" 26 30 #include "util/callchain.h"
+6 -2
tools/perf/builtin-top.c
··· 101 101 102 102 static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he) 103 103 { 104 - struct perf_evsel *evsel = hists_to_evsel(he->hists); 104 + struct perf_evsel *evsel; 105 105 struct symbol *sym; 106 106 struct annotation *notes; 107 107 struct map *map; ··· 109 109 110 110 if (!he || !he->ms.sym) 111 111 return -1; 112 + 113 + evsel = hists_to_evsel(he->hists); 112 114 113 115 sym = he->ms.sym; 114 116 map = he->ms.map; ··· 228 226 static void perf_top__show_details(struct perf_top *top) 229 227 { 230 228 struct hist_entry *he = top->sym_filter_entry; 231 - struct perf_evsel *evsel = hists_to_evsel(he->hists); 229 + struct perf_evsel *evsel; 232 230 struct annotation *notes; 233 231 struct symbol *symbol; 234 232 int more; 235 233 236 234 if (!he) 237 235 return; 236 + 237 + evsel = hists_to_evsel(he->hists); 238 238 239 239 symbol = he->ms.sym; 240 240 notes = symbol__annotation(symbol);
+4 -3
tools/perf/builtin-trace.c
··· 61 61 #include <linux/random.h> 62 62 #include <linux/stringify.h> 63 63 #include <linux/time64.h> 64 + #include <linux/zalloc.h> 64 65 #include <fcntl.h> 65 66 #include <sys/sysmacros.h> 66 67 ··· 1039 1038 { 1040 1039 struct thread_trace *ttrace = zalloc(sizeof(struct thread_trace)); 1041 1040 1042 - if (ttrace) 1041 + if (ttrace) { 1043 1042 ttrace->files.max = -1; 1044 - 1045 - ttrace->syscall_stats = intlist__new(NULL); 1043 + ttrace->syscall_stats = intlist__new(NULL); 1044 + } 1046 1045 1047 1046 return ttrace; 1048 1047 }
+1 -1
tools/perf/perf.c
··· 18 18 #include "util/bpf-loader.h" 19 19 #include "util/debug.h" 20 20 #include "util/event.h" 21 - #include "util/util.h" 22 21 #include <api/fs/fs.h> 23 22 #include <api/fs/tracing_path.h> 24 23 #include <errno.h> ··· 29 30 #include <sys/stat.h> 30 31 #include <unistd.h> 31 32 #include <linux/kernel.h> 33 + #include <linux/zalloc.h> 32 34 33 35 const char perf_usage_string[] = 34 36 "perf [--version] [--help] [OPTIONS] COMMAND [ARGS]";
+1 -1
tools/perf/pmu-events/jevents.c
··· 407 407 408 408 list_for_each_entry_safe(es, next, &arch_std_events, list) { 409 409 FOR_ALL_EVENT_STRUCT_FIELDS(FREE_EVENT_FIELD); 410 - list_del(&es->list); 410 + list_del_init(&es->list); 411 411 free(es); 412 412 } 413 413 }
+1 -1
tools/perf/scripts/python/export-to-postgresql.py
··· 898 898 if is_table_empty("ptwrite"): 899 899 drop("ptwrite") 900 900 if is_table_empty("mwait") and is_table_empty("pwre") and is_table_empty("exstop") and is_table_empty("pwrx"): 901 + do_query(query, 'DROP VIEW power_events_view'); 901 902 drop("mwait") 902 903 drop("pwre") 903 904 drop("exstop") 904 905 drop("pwrx") 905 - do_query(query, 'DROP VIEW power_events_view'); 906 906 if is_table_empty("cbr"): 907 907 drop("cbr") 908 908
+1 -1
tools/perf/scripts/python/export-to-sqlite.py
··· 608 608 if is_table_empty("ptwrite"): 609 609 drop("ptwrite") 610 610 if is_table_empty("mwait") and is_table_empty("pwre") and is_table_empty("exstop") and is_table_empty("pwrx"): 611 + do_query(query, 'DROP VIEW power_events_view'); 611 612 drop("mwait") 612 613 drop("pwre") 613 614 drop("exstop") 614 615 drop("pwrx") 615 - do_query(query, 'DROP VIEW power_events_view'); 616 616 if is_table_empty("cbr"): 617 617 drop("cbr") 618 618
+3 -2
tools/perf/tests/dwarf-unwind.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include <linux/compiler.h> 3 3 #include <linux/types.h> 4 + #include <linux/zalloc.h> 4 5 #include <inttypes.h> 5 6 #include <unistd.h> 6 7 #include "tests.h" ··· 116 115 } 117 116 118 117 out: 119 - free(sample.user_stack.data); 120 - free(sample.user_regs.regs); 118 + zfree(&sample.user_stack.data); 119 + zfree(&sample.user_regs.regs); 121 120 return err; 122 121 } 123 122
+2 -1
tools/perf/tests/expr.c
··· 3 3 #include "util/expr.h" 4 4 #include "tests.h" 5 5 #include <stdlib.h> 6 + #include <linux/zalloc.h> 6 7 7 8 static int test(struct parse_ctx *ctx, const char *e, double val2) 8 9 { ··· 59 58 TEST_ASSERT_VAL("find other", other[3] == NULL); 60 59 61 60 for (i = 0; i < num_other; i++) 62 - free((void *)other[i]); 61 + zfree(&other[i]); 63 62 free((void *)other); 64 63 65 64 return 0;
+1
tools/perf/tests/llvm.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include <stdio.h> 3 + #include <stdlib.h> 3 4 #include <bpf/libbpf.h> 4 5 #include <util/llvm-utils.h> 5 6 #include <util/cache.h>
+2 -1
tools/perf/tests/mem2node.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include <linux/compiler.h> 3 3 #include <linux/bitmap.h> 4 + #include <linux/zalloc.h> 4 5 #include "cpumap.h" 5 6 #include "mem2node.h" 6 7 #include "tests.h" ··· 68 67 T("failed: mem2node__node", -1 == mem2node__node(&map, 0x1050)); 69 68 70 69 for (i = 0; i < ARRAY_SIZE(nodes); i++) 71 - free(nodes[i].set); 70 + zfree(&nodes[i].set); 72 71 73 72 mem2node__exit(&map); 74 73 return 0;
+1 -1
tools/perf/tests/mmap-thread-lookup.c
··· 53 53 { 54 54 struct thread_data *td = arg; 55 55 ssize_t ret; 56 - int go; 56 + int go = 0; 57 57 58 58 if (thread_init(td)) 59 59 return NULL;
+1
tools/perf/tests/sample-parsing.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include <stdbool.h> 3 3 #include <inttypes.h> 4 + #include <stdlib.h> 4 5 #include <linux/bitops.h> 5 6 #include <linux/kernel.h> 6 7 #include <linux/types.h>
+2 -1
tools/perf/tests/switch-tracking.c
··· 4 4 #include <errno.h> 5 5 #include <time.h> 6 6 #include <stdlib.h> 7 + #include <linux/zalloc.h> 7 8 8 9 #include "parse-events.h" 9 10 #include "evlist.h" ··· 238 237 239 238 while (!list_empty(events)) { 240 239 node = list_entry(events->next, struct event_node, list); 241 - list_del(&node->list); 240 + list_del_init(&node->list); 242 241 free(node); 243 242 } 244 243 }
+2 -1
tools/perf/tests/thread-map.c
··· 6 6 #include "tests.h" 7 7 #include "thread_map.h" 8 8 #include "debug.h" 9 + #include <linux/zalloc.h> 9 10 10 11 #define NAME (const char *) "perf" 11 12 #define NAMEUL (unsigned long) NAME ··· 134 133 thread_map__remove(threads, 0)); 135 134 136 135 for (i = 0; i < threads->nr; i++) 137 - free(threads->map[i].comm); 136 + zfree(&threads->map[i].comm); 138 137 139 138 free(threads); 140 139 return 0;
+1
tools/perf/tests/vmlinux-kallsyms.c
··· 3 3 #include <linux/rbtree.h> 4 4 #include <inttypes.h> 5 5 #include <string.h> 6 + #include <stdlib.h> 6 7 #include "map.h" 7 8 #include "symbol.h" 8 9 #include "util.h"
+1 -1
tools/perf/ui/browser.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 - #include "../util.h" 3 2 #include "../string2.h" 4 3 #include "../config.h" 5 4 #include "../../perf.h" ··· 16 17 #include "keysyms.h" 17 18 #include "../color.h" 18 19 #include <linux/ctype.h> 20 + #include <linux/zalloc.h> 19 21 20 22 static int ui_browser__percent_color(struct ui_browser *browser, 21 23 double percent, bool current)
+1
tools/perf/ui/browser.h
··· 4 4 5 5 #include <linux/types.h> 6 6 #include <stdarg.h> 7 + #include <sys/types.h> 7 8 8 9 #define HE_COLORSET_TOP 50 9 10 #define HE_COLORSET_MEDIUM 51
+1 -1
tools/perf/ui/browsers/annotate.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 - #include "../../util/util.h" 3 2 #include "../browser.h" 4 3 #include "../helpline.h" 5 4 #include "../ui.h" ··· 14 15 #include <pthread.h> 15 16 #include <linux/kernel.h> 16 17 #include <linux/string.h> 18 + #include <linux/zalloc.h> 17 19 #include <sys/ttydefaults.h> 18 20 #include <asm/bug.h> 19 21
+12 -5
tools/perf/ui/browsers/hists.c
··· 9 9 #include <linux/string.h> 10 10 #include <sys/ttydefaults.h> 11 11 #include <linux/time64.h> 12 + #include <linux/zalloc.h> 12 13 13 14 #include "../../util/callchain.h" 14 15 #include "../../util/evsel.h" ··· 19 18 #include "../../util/symbol.h" 20 19 #include "../../util/pstack.h" 21 20 #include "../../util/sort.h" 22 - #include "../../util/util.h" 23 21 #include "../../util/top.h" 24 22 #include "../../util/thread.h" 25 23 #include "../../arch/common.h" ··· 639 639 switch (key) { 640 640 case K_TIMER: { 641 641 u64 nr_entries; 642 - hbt->timer(hbt->arg); 642 + 643 + WARN_ON_ONCE(!hbt); 644 + 645 + if (hbt) 646 + hbt->timer(hbt->arg); 643 647 644 648 if (hist_browser__has_filter(browser) || 645 649 symbol_conf.report_hierarchy) ··· 2825 2821 { 2826 2822 struct hists *hists = evsel__hists(evsel); 2827 2823 struct hist_browser *browser = perf_evsel_browser__new(evsel, hbt, env, annotation_opts); 2828 - struct branch_info *bi; 2824 + struct branch_info *bi = NULL; 2829 2825 #define MAX_OPTIONS 16 2830 2826 char *options[MAX_OPTIONS]; 2831 2827 struct popup_action actions[MAX_OPTIONS]; ··· 3091 3087 goto skip_annotation; 3092 3088 3093 3089 if (sort__mode == SORT_MODE__BRANCH) { 3094 - bi = browser->he_selection->branch_info; 3090 + 3091 + if (browser->he_selection) 3092 + bi = browser->he_selection->branch_info; 3095 3093 3096 3094 if (bi == NULL) 3097 3095 goto skip_annotation; ··· 3277 3271 3278 3272 switch (key) { 3279 3273 case K_TIMER: 3280 - hbt->timer(hbt->arg); 3274 + if (hbt) 3275 + hbt->timer(hbt->arg); 3281 3276 3282 3277 if (!menu->lost_events_warned && 3283 3278 menu->lost_events &&
+1
tools/perf/ui/browsers/map.c
··· 2 2 #include <elf.h> 3 3 #include <inttypes.h> 4 4 #include <sys/ttydefaults.h> 5 + #include <stdlib.h> 5 6 #include <string.h> 6 7 #include <linux/bitops.h> 7 8 #include "../../util/util.h"
+3 -3
tools/perf/ui/browsers/res_sample.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* Display a menu with individual samples to browse with perf script */ 3 - #include "util.h" 4 3 #include "hist.h" 5 4 #include "evsel.h" 6 5 #include "hists.h" ··· 7 8 #include "config.h" 8 9 #include "time-utils.h" 9 10 #include <linux/time64.h> 11 + #include <linux/zalloc.h> 10 12 11 13 static u64 context_len = 10 * NSEC_PER_MSEC; 12 14 ··· 46 46 if (asprintf(&names[i], "%s: CPU %d tid %d", tbuf, 47 47 res_samples[i].cpu, res_samples[i].tid) < 0) { 48 48 while (--i >= 0) 49 - free(names[i]); 49 + zfree(&names[i]); 50 50 free(names); 51 51 return -1; 52 52 } 53 53 } 54 54 choice = ui__popup_menu(num_res, names); 55 55 for (i = 0; i < num_res; i++) 56 - free(names[i]); 56 + zfree(&names[i]); 57 57 free(names); 58 58 59 59 if (choice < 0 || choice >= num_res)
+2 -2
tools/perf/ui/browsers/scripts.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include "../../util/sort.h" 3 - #include "../../util/util.h" 4 3 #include "../../util/hist.h" 5 4 #include "../../util/debug.h" 6 5 #include "../../util/symbol.h" 7 6 #include "../browser.h" 8 7 #include "../libslang.h" 9 8 #include "config.h" 9 + #include <linux/zalloc.h> 10 10 11 11 #define SCRIPT_NAMELEN 128 12 12 #define SCRIPT_MAX_NO 64 ··· 142 142 out: 143 143 free(buf); 144 144 for (i = 0; i < max_std; i++) 145 - free(paths[i]); 145 + zfree(&paths[i]); 146 146 return ret; 147 147 } 148 148
+1 -1
tools/perf/ui/gtk/annotate.c
··· 152 152 gtk_container_add(GTK_CONTAINER(window), view); 153 153 154 154 list_for_each_entry_safe(pos, n, &notes->src->source, al.node) { 155 - list_del(&pos->al.node); 155 + list_del_init(&pos->al.node); 156 156 disasm_line__free(pos); 157 157 } 158 158
+1 -2
tools/perf/ui/gtk/util.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include "../util.h" 3 - #include "../../util/util.h" 4 3 #include "../../util/debug.h" 5 4 #include "gtk.h" 6 5 7 6 #include <string.h> 8 - 7 + #include <linux/zalloc.h> 9 8 10 9 struct perf_gtk_context *pgctx; 11 10
+1 -1
tools/perf/ui/stdio/hist.c
··· 3 3 #include <linux/string.h> 4 4 5 5 #include "../../util/callchain.h" 6 - #include "../../util/util.h" 7 6 #include "../../util/hist.h" 8 7 #include "../../util/map.h" 9 8 #include "../../util/map_groups.h" ··· 13 14 #include "../../util/string2.h" 14 15 #include "../../util/thread.h" 15 16 #include <linux/ctype.h> 17 + #include <linux/zalloc.h> 16 18 17 19 static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin) 18 20 {
+1
tools/perf/ui/tui/setup.c
··· 2 2 #include <errno.h> 3 3 #include <signal.h> 4 4 #include <stdbool.h> 5 + #include <stdlib.h> 5 6 #include <linux/kernel.h> 6 7 #ifdef HAVE_BACKTRACE_SUPPORT 7 8 #include <execinfo.h>
+1 -1
tools/perf/ui/tui/util.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 - #include "../../util/util.h" 3 2 #include <signal.h> 4 3 #include <stdbool.h> 5 4 #include <string.h> 5 + #include <stdlib.h> 6 6 #include <sys/ttydefaults.h> 7 7 8 8 #include "../../util/cache.h"
+5
tools/perf/util/Build
··· 25 25 perf-y += libstring.o 26 26 perf-y += bitmap.o 27 27 perf-y += hweight.o 28 + perf-y += zalloc.o 28 29 perf-y += smt.o 29 30 perf-y += strbuf.o 30 31 perf-y += string.o ··· 240 239 $(call if_changed_dep,cc_o_c) 241 240 242 241 $(OUTPUT)util/vsprintf.o: ../lib/vsprintf.c FORCE 242 + $(call rule_mkdir) 243 + $(call if_changed_dep,cc_o_c) 244 + 245 + $(OUTPUT)util/zalloc.o: ../lib/zalloc.c FORCE 243 246 $(call rule_mkdir) 244 247 $(call if_changed_dep,cc_o_c)
+5 -8
tools/perf/util/annotate.c
··· 1119 1119 *namep = strdup(name); 1120 1120 1121 1121 if (*namep == NULL) 1122 - goto out_free_name; 1122 + goto out; 1123 1123 1124 1124 (*rawp)[0] = tmp; 1125 1125 *rawp = skip_spaces(*rawp); 1126 1126 1127 1127 return 0; 1128 1128 1129 - out_free_name: 1130 - free((void *)namep); 1131 - *namep = NULL; 1129 + out: 1132 1130 return -1; 1133 1131 } 1134 1132 ··· 1235 1237 dl->ins.ops->free(&dl->ops); 1236 1238 else 1237 1239 ins__delete(&dl->ops); 1238 - free((void *)dl->ins.name); 1239 - dl->ins.name = NULL; 1240 + zfree(&dl->ins.name); 1240 1241 annotation_line__delete(&dl->al); 1241 1242 } 1242 1243 ··· 1586 1589 return; 1587 1590 } 1588 1591 1589 - list_del(&dl->al.node); 1592 + list_del_init(&dl->al.node); 1590 1593 disasm_line__free(dl); 1591 1594 } 1592 1595 } ··· 2463 2466 struct annotation_line *al, *n; 2464 2467 2465 2468 list_for_each_entry_safe(al, n, &as->source, node) { 2466 - list_del(&al->node); 2469 + list_del_init(&al->node); 2467 2470 disasm_line__free(disasm_line(al)); 2468 2471 } 2469 2472 }
+1 -1
tools/perf/util/arm-spe.c
··· 12 12 #include <linux/types.h> 13 13 #include <linux/bitops.h> 14 14 #include <linux/log2.h> 15 + #include <linux/zalloc.h> 15 16 16 17 #include "cpumap.h" 17 18 #include "color.h" ··· 20 19 #include "evlist.h" 21 20 #include "machine.h" 22 21 #include "session.h" 23 - #include "util.h" 24 22 #include "thread.h" 25 23 #include "debug.h" 26 24 #include "auxtrace.h"
+5 -6
tools/perf/util/auxtrace.c
··· 24 24 #include <stdlib.h> 25 25 #include <stdio.h> 26 26 #include <linux/list.h> 27 + #include <linux/zalloc.h> 27 28 28 29 #include "../perf.h" 29 - #include "util.h" 30 30 #include "evlist.h" 31 31 #include "dso.h" 32 32 #include "map.h" ··· 408 408 409 409 buffer = list_entry(queues->queue_array[i].head.next, 410 410 struct auxtrace_buffer, list); 411 - list_del(&buffer->list); 411 + list_del_init(&buffer->list); 412 412 auxtrace_buffer__free(buffer); 413 413 } 414 414 } ··· 612 612 struct auxtrace_index *auxtrace_index, *n; 613 613 614 614 list_for_each_entry_safe(auxtrace_index, n, head, list) { 615 - list_del(&auxtrace_index->list); 615 + list_del_init(&auxtrace_index->list); 616 616 free(auxtrace_index); 617 617 } 618 618 } ··· 1413 1413 return; 1414 1414 1415 1415 auxtrace_cache__drop(c); 1416 - free(c->hashtable); 1416 + zfree(&c->hashtable); 1417 1417 free(c); 1418 1418 } 1419 1419 ··· 1459 1459 1460 1460 static void addr_filter__free_str(struct addr_filter *filt) 1461 1461 { 1462 - free(filt->str); 1462 + zfree(&filt->str); 1463 1463 filt->action = NULL; 1464 1464 filt->sym_from = NULL; 1465 1465 filt->sym_to = NULL; 1466 1466 filt->filename = NULL; 1467 - filt->str = NULL; 1468 1467 } 1469 1468 1470 1469 static struct addr_filter *addr_filter__new(void)
+2 -1
tools/perf/util/bpf-loader.c
··· 12 12 #include <linux/err.h> 13 13 #include <linux/kernel.h> 14 14 #include <linux/string.h> 15 + #include <linux/zalloc.h> 15 16 #include <errno.h> 16 17 #include "perf.h" 17 18 #include "debug.h" ··· 829 828 bpf_map_op__delete(struct bpf_map_op *op) 830 829 { 831 830 if (!list_empty(&op->list)) 832 - list_del(&op->list); 831 + list_del_init(&op->list); 833 832 if (op->key_type == BPF_MAP_KEY_RANGES) 834 833 parse_events__clear_array(&op->k.array); 835 834 free(op);
+1
tools/perf/util/build-id.c
··· 30 30 #include "strlist.h" 31 31 32 32 #include <linux/ctype.h> 33 + #include <linux/zalloc.h> 33 34 34 35 static bool no_buildid_cache; 35 36
+3 -2
tools/perf/util/call-path.c
··· 6 6 7 7 #include <linux/rbtree.h> 8 8 #include <linux/list.h> 9 + #include <linux/zalloc.h> 10 + #include <stdlib.h> 9 11 10 - #include "util.h" 11 12 #include "call-path.h" 12 13 13 14 static void call_path__init(struct call_path *cp, struct call_path *parent, ··· 40 39 struct call_path_block *pos, *n; 41 40 42 41 list_for_each_entry_safe(pos, n, &cpr->blocks, node) { 43 - list_del(&pos->node); 42 + list_del_init(&pos->node); 44 43 free(pos); 45 44 } 46 45 free(cpr);
+6 -6
tools/perf/util/callchain.c
··· 16 16 #include <stdbool.h> 17 17 #include <errno.h> 18 18 #include <math.h> 19 + #include <linux/zalloc.h> 19 20 20 21 #include "asm/bug.h" 21 22 22 23 #include "hist.h" 23 - #include "util.h" 24 24 #include "sort.h" 25 25 #include "machine.h" 26 26 #include "map.h" ··· 636 636 struct callchain_list *call, *tmp; 637 637 638 638 list_for_each_entry_safe(call, tmp, &new->val, list) { 639 - list_del(&call->list); 639 + list_del_init(&call->list); 640 640 map__zput(call->ms.map); 641 641 free(call); 642 642 } ··· 1002 1002 callchain_cursor_append(cursor, list->ip, 1003 1003 list->ms.map, list->ms.sym, 1004 1004 false, NULL, 0, 0, 0, list->srcline); 1005 - list_del(&list->list); 1005 + list_del_init(&list->list); 1006 1006 map__zput(list->ms.map); 1007 1007 free(list); 1008 1008 } ··· 1453 1453 struct rb_node *n; 1454 1454 1455 1455 list_for_each_entry_safe(list, tmp, &node->parent_val, list) { 1456 - list_del(&list->list); 1456 + list_del_init(&list->list); 1457 1457 map__zput(list->ms.map); 1458 1458 free(list); 1459 1459 } 1460 1460 1461 1461 list_for_each_entry_safe(list, tmp, &node->val, list) { 1462 - list_del(&list->list); 1462 + list_del_init(&list->list); 1463 1463 map__zput(list->ms.map); 1464 1464 free(list); 1465 1465 } ··· 1544 1544 1545 1545 out: 1546 1546 list_for_each_entry_safe(chain, new, &head, list) { 1547 - list_del(&chain->list); 1547 + list_del_init(&chain->list); 1548 1548 map__zput(chain->ms.map); 1549 1549 free(chain); 1550 1550 }
+2 -2
tools/perf/util/cgroup.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 - #include "util.h" 3 2 #include "../perf.h" 4 3 #include <subcmd/parse-options.h> 5 4 #include "evsel.h" 6 5 #include "cgroup.h" 7 6 #include "evlist.h" 8 7 #include <linux/stringify.h> 8 + #include <linux/zalloc.h> 9 9 #include <sys/types.h> 10 10 #include <sys/stat.h> 11 11 #include <fcntl.h> ··· 124 124 return cgroup; 125 125 126 126 out_free_name: 127 - free(cgroup->name); 127 + zfree(&cgroup->name); 128 128 out_err: 129 129 free(cgroup); 130 130 return NULL;
+1 -1
tools/perf/util/comm.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include "comm.h" 3 - #include "util.h" 4 3 #include <errno.h> 5 4 #include <stdlib.h> 6 5 #include <stdio.h> 7 6 #include <string.h> 8 7 #include <linux/refcount.h> 9 8 #include <linux/rbtree.h> 9 + #include <linux/zalloc.h> 10 10 #include "rwsem.h" 11 11 12 12 struct comm_str {
+1 -2
tools/perf/util/config.c
··· 11 11 */ 12 12 #include <errno.h> 13 13 #include <sys/param.h> 14 - #include "util.h" 15 14 #include "cache.h" 16 15 #include "callchain.h" 17 16 #include <subcmd/exec-cmd.h> ··· 22 23 #include <sys/stat.h> 23 24 #include <unistd.h> 24 25 #include <linux/string.h> 25 - 26 + #include <linux/zalloc.h> 26 27 #include <linux/ctype.h> 27 28 28 29 #define MAXNAME (256)
+1 -1
tools/perf/util/counts.c
··· 3 3 #include <stdlib.h> 4 4 #include "evsel.h" 5 5 #include "counts.h" 6 - #include "util.h" 6 + #include <linux/zalloc.h> 7 7 8 8 struct perf_counts *perf_counts__new(int ncpus, int nthreads) 9 9 {
+1 -1
tools/perf/util/cpumap.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 - #include "util.h" 3 2 #include <api/fs/fs.h> 4 3 #include "../perf.h" 5 4 #include "cpumap.h" ··· 10 11 #include "asm/bug.h" 11 12 12 13 #include <linux/ctype.h> 14 + #include <linux/zalloc.h> 13 15 14 16 static int max_cpu_num; 15 17 static int max_present_cpu_num;
+3 -2
tools/perf/util/cputopo.c
··· 2 2 #include <sys/param.h> 3 3 #include <sys/utsname.h> 4 4 #include <inttypes.h> 5 + #include <stdlib.h> 5 6 #include <api/fs/fs.h> 7 + #include <linux/zalloc.h> 6 8 7 9 #include "cputopo.h" 8 10 #include "cpumap.h" 9 - #include "util.h" 10 11 #include "env.h" 11 12 12 13 #define CORE_SIB_FMT \ ··· 344 343 u32 i; 345 344 346 345 for (i = 0; i < tp->nr; i++) 347 - free(tp->nodes[i].cpus); 346 + zfree(&tp->nodes[i].cpus); 348 347 349 348 free(tp); 350 349 }
+1
tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
··· 8 8 9 9 #include <linux/err.h> 10 10 #include <linux/list.h> 11 + #include <linux/zalloc.h> 11 12 #include <stdlib.h> 12 13 #include <opencsd/c_api/opencsd_c_api.h> 13 14 #include <opencsd/etmv4/trc_pkt_types_etmv4.h>
+4 -4
tools/perf/util/cs-etm.c
··· 11 11 #include <linux/kernel.h> 12 12 #include <linux/log2.h> 13 13 #include <linux/types.h> 14 + #include <linux/zalloc.h> 14 15 15 16 #include <opencsd/ocsd_if_types.h> 16 17 #include <stdlib.h> ··· 555 554 etmq->traceid_queues_list = NULL; 556 555 557 556 /* finally free the traceid_queues array */ 558 - free(etmq->traceid_queues); 559 - etmq->traceid_queues = NULL; 557 + zfree(&etmq->traceid_queues); 560 558 } 561 559 562 560 static void cs_etm__free_queue(void *priv) ··· 2538 2538 return 0; 2539 2539 } 2540 2540 2541 - if (session->itrace_synth_opts && session->itrace_synth_opts->set) { 2541 + if (session->itrace_synth_opts->set) { 2542 2542 etm->synth_opts = *session->itrace_synth_opts; 2543 2543 } else { 2544 2544 itrace_synth_opts__set_default(&etm->synth_opts, ··· 2568 2568 err_free_metadata: 2569 2569 /* No need to check @metadata[j], free(NULL) is supported */ 2570 2570 for (j = 0; j < num_cpu; j++) 2571 - free(metadata[j]); 2571 + zfree(&metadata[j]); 2572 2572 zfree(&metadata); 2573 2573 err_free_traceid_list: 2574 2574 intlist__delete(traceid_list);
+2 -2
tools/perf/util/data-convert-bt.c
··· 10 10 #include <inttypes.h> 11 11 #include <linux/compiler.h> 12 12 #include <linux/kernel.h> 13 + #include <linux/zalloc.h> 13 14 #include <babeltrace/ctf-writer/writer.h> 14 15 #include <babeltrace/ctf-writer/clock.h> 15 16 #include <babeltrace/ctf-writer/stream.h> ··· 23 22 #include "asm/bug.h" 24 23 #include "data-convert-bt.h" 25 24 #include "session.h" 26 - #include "util.h" 27 25 #include "debug.h" 28 26 #include "tool.h" 29 27 #include "evlist.h" ··· 1353 1353 for (cpu = 0; cpu < cw->stream_cnt; cpu++) 1354 1354 ctf_stream__delete(cw->stream[cpu]); 1355 1355 1356 - free(cw->stream); 1356 + zfree(&cw->stream); 1357 1357 } 1358 1358 1359 1359 static int ctf_writer__setup_env(struct ctf_writer *cw,
+2 -1
tools/perf/util/data.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include <linux/compiler.h> 3 3 #include <linux/kernel.h> 4 + #include <linux/zalloc.h> 4 5 #include <sys/types.h> 5 6 #include <sys/stat.h> 6 7 #include <errno.h> ··· 21 20 { 22 21 while (--nr >= 1) { 23 22 close(files[nr].fd); 24 - free(files[nr].path); 23 + zfree(&files[nr].path); 25 24 } 26 25 free(files); 27 26 }
+4 -3
tools/perf/util/db-export.c
··· 5 5 */ 6 6 7 7 #include <errno.h> 8 + #include <stdlib.h> 8 9 9 10 #include "evsel.h" 10 11 #include "machine.h" ··· 14 13 #include "symbol.h" 15 14 #include "map.h" 16 15 #include "event.h" 17 - #include "util.h" 18 16 #include "thread-stack.h" 19 17 #include "callchain.h" 20 18 #include "call-path.h" 21 19 #include "db-export.h" 20 + #include <linux/zalloc.h> 22 21 23 22 struct deferred_export { 24 23 struct list_head node; ··· 34 33 de = list_entry(dbe->deferred.next, struct deferred_export, 35 34 node); 36 35 err = dbe->export_comm(dbe, de->comm); 37 - list_del(&de->node); 36 + list_del_init(&de->node); 38 37 free(de); 39 38 if (err) 40 39 return err; ··· 50 49 while (!list_empty(&dbe->deferred)) { 51 50 de = list_entry(dbe->deferred.next, struct deferred_export, 52 51 node); 53 - list_del(&de->node); 52 + list_del_init(&de->node); 54 53 free(de); 55 54 } 56 55 }
+1
tools/perf/util/debug.c
··· 7 7 #include <string.h> 8 8 #include <stdarg.h> 9 9 #include <stdio.h> 10 + #include <stdlib.h> 10 11 #include <sys/wait.h> 11 12 #include <api/debug.h> 12 13 #include <linux/time64.h>
+2 -1
tools/perf/util/demangle-java.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include <sys/types.h> 3 3 #include <stdio.h> 4 + #include <stdlib.h> 4 5 #include <string.h> 5 - #include "util.h" 6 6 #include "debug.h" 7 7 #include "symbol.h" 8 8 9 9 #include "demangle-java.h" 10 10 11 11 #include <linux/ctype.h> 12 + #include <linux/kernel.h> 12 13 13 14 enum { 14 15 MODE_PREFIX = 0,
+3 -2
tools/perf/util/dso.c
··· 2 2 #include <asm/bug.h> 3 3 #include <linux/kernel.h> 4 4 #include <linux/string.h> 5 + #include <linux/zalloc.h> 5 6 #include <sys/time.h> 6 7 #include <sys/resource.h> 7 8 #include <sys/types.h> ··· 22 21 #include "dso.h" 23 22 #include "machine.h" 24 23 #include "auxtrace.h" 25 - #include "util.h" 24 + #include "util.h" /* O_CLOEXEC for older systems */ 26 25 #include "debug.h" 27 26 #include "string2.h" 28 27 #include "vdso.h" ··· 434 433 435 434 static void dso__list_del(struct dso *dso) 436 435 { 437 - list_del(&dso->data.open_entry); 436 + list_del_init(&dso->data.open_entry); 438 437 WARN_ONCE(dso__data_open_cnt <= 0, 439 438 "DSO data fd counter out of bounds."); 440 439 dso__data_open_cnt--;
+1 -1
tools/perf/util/dwarf-aux.c
··· 6 6 #include <errno.h> 7 7 #include <inttypes.h> 8 8 #include <stdbool.h> 9 - #include "util.h" 9 + #include <stdlib.h> 10 10 #include "debug.h" 11 11 #include "dwarf-aux.h" 12 12 #include "string2.h"
+6 -5
tools/perf/util/env.c
··· 2 2 #include "cpumap.h" 3 3 #include "env.h" 4 4 #include <linux/ctype.h> 5 - #include "util.h" 5 + #include <linux/zalloc.h> 6 6 #include "bpf-event.h" 7 7 #include <errno.h> 8 8 #include <sys/utsname.h> 9 9 #include <bpf/libbpf.h> 10 + #include <stdlib.h> 10 11 11 12 struct perf_env perf_env; 12 13 ··· 187 186 zfree(&env->caches); 188 187 189 188 for (i = 0; i < env->nr_memory_nodes; i++) 190 - free(env->memory_nodes[i].set); 189 + zfree(&env->memory_nodes[i].set); 191 190 zfree(&env->memory_nodes); 192 191 } 193 192 ··· 287 286 288 287 void cpu_cache_level__free(struct cpu_cache_level *cache) 289 288 { 290 - free(cache->type); 291 - free(cache->map); 292 - free(cache->size); 289 + zfree(&cache->type); 290 + zfree(&cache->map); 291 + zfree(&cache->size); 293 292 } 294 293 295 294 /*
+2 -1
tools/perf/util/event.c
··· 11 11 #include <uapi/linux/mman.h> /* To get things like MAP_HUGETLB even on older libc headers */ 12 12 #include <api/fs/fs.h> 13 13 #include <linux/perf_event.h> 14 + #include <linux/zalloc.h> 14 15 #include "event.h" 15 16 #include "debug.h" 16 17 #include "hist.h" ··· 856 855 free(synthesize_threads); 857 856 free_dirent: 858 857 for (i = 0; i < n; i++) 859 - free(dirent[i]); 858 + zfree(&dirent[i]); 860 859 free(dirent); 861 860 862 861 return err;
+1 -1
tools/perf/util/evlist.c
··· 5 5 * Parts came from builtin-{top,stat,record}.c, see those files for further 6 6 * copyright notes. 7 7 */ 8 - #include "util.h" 9 8 #include <api/fs/fs.h> 10 9 #include <errno.h> 11 10 #include <inttypes.h> ··· 32 33 #include <linux/hash.h> 33 34 #include <linux/log2.h> 34 35 #include <linux/err.h> 36 + #include <linux/zalloc.h> 35 37 36 38 #ifdef LACKS_SIGQUEUE_PROTOTYPE 37 39 int sigqueue(pid_t pid, int sig, const union sigval value);
+2 -2
tools/perf/util/evsel.c
··· 17 17 #include <linux/perf_event.h> 18 18 #include <linux/compiler.h> 19 19 #include <linux/err.h> 20 + #include <linux/zalloc.h> 20 21 #include <sys/ioctl.h> 21 22 #include <sys/resource.h> 22 23 #include <sys/types.h> ··· 28 27 #include "event.h" 29 28 #include "evsel.h" 30 29 #include "evlist.h" 31 - #include "util.h" 32 30 #include "cpumap.h" 33 31 #include "thread_map.h" 34 32 #include "target.h" ··· 1298 1298 struct perf_evsel_config_term *term, *h; 1299 1299 1300 1300 list_for_each_entry_safe(term, h, &evsel->config_terms, list) { 1301 - list_del(&term->list); 1301 + list_del_init(&term->list); 1302 1302 free(term); 1303 1303 } 1304 1304 }
+3 -3
tools/perf/util/get_current_dir_name.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - // Copyright (C) 2018, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com> 1 + // SPDX-License-Identifier: LGPL-2.1 2 + // Copyright (C) 2018, 2019 Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com> 3 3 // 4 4 #ifndef HAVE_GET_CURRENT_DIR_NAME 5 - #include "util.h" 5 + #include "get_current_dir_name.h" 6 6 #include <unistd.h> 7 7 #include <stdlib.h> 8 8 #include <stdlib.h>
+8
tools/perf/util/get_current_dir_name.h
··· 1 + // SPDX-License-Identifier: LGPL-2.1 2 + // Copyright (C) 2018, 2019 Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com> 3 + // 4 + #ifndef __PERF_GET_CURRENT_DIR_NAME_H 5 + #ifndef HAVE_GET_CURRENT_DIR_NAME 6 + char *get_current_dir_name(void); 7 + #endif // HAVE_GET_CURRENT_DIR_NAME 8 + #endif // __PERF_GET_CURRENT_DIR_NAME_H
+4 -4
tools/perf/util/header.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include <errno.h> 3 3 #include <inttypes.h> 4 - #include "util.h" 5 4 #include "string2.h" 6 5 #include <sys/param.h> 7 6 #include <sys/types.h> ··· 14 15 #include <linux/bitops.h> 15 16 #include <linux/string.h> 16 17 #include <linux/stringify.h> 18 + #include <linux/zalloc.h> 17 19 #include <sys/stat.h> 18 20 #include <sys/utsname.h> 19 21 #include <linux/time64.h> ··· 1052 1052 1053 1053 scnprintf(file, PATH_MAX, "%s/size", path); 1054 1054 if (sysfs__read_str(file, &cache->size, &len)) { 1055 - free(cache->type); 1055 + zfree(&cache->type); 1056 1056 return -1; 1057 1057 } 1058 1058 ··· 1061 1061 1062 1062 scnprintf(file, PATH_MAX, "%s/shared_cpu_list", path); 1063 1063 if (sysfs__read_str(file, &cache->map, &len)) { 1064 - free(cache->map); 1065 - free(cache->type); 1064 + zfree(&cache->map); 1065 + zfree(&cache->type); 1066 1066 return -1; 1067 1067 } 1068 1068
+2
tools/perf/util/help-unknown-cmd.c
··· 3 3 #include "config.h" 4 4 #include <poll.h> 5 5 #include <stdio.h> 6 + #include <stdlib.h> 6 7 #include <subcmd/help.h> 7 8 #include "../builtin.h" 8 9 #include "levenshtein.h" 10 + #include <linux/zalloc.h> 9 11 10 12 static int autocorrect; 11 13
+10 -10
tools/perf/util/hist.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include "callchain.h" 3 - #include "util.h" 4 3 #include "build-id.h" 5 4 #include "hist.h" 6 5 #include "map.h" ··· 19 20 #include <inttypes.h> 20 21 #include <sys/param.h> 21 22 #include <linux/time64.h> 23 + #include <linux/zalloc.h> 22 24 23 25 static bool hists__filter_entry_by_dso(struct hists *hists, 24 26 struct hist_entry *he); ··· 472 472 return 0; 473 473 474 474 err_srcline: 475 - free(he->srcline); 475 + zfree(&he->srcline); 476 476 477 477 err_rawdata: 478 - free(he->raw_data); 478 + zfree(&he->raw_data); 479 479 480 480 err_infos: 481 481 if (he->branch_info) { 482 482 map__put(he->branch_info->from.map); 483 483 map__put(he->branch_info->to.map); 484 - free(he->branch_info); 484 + zfree(&he->branch_info); 485 485 } 486 486 if (he->mem_info) { 487 487 map__put(he->mem_info->iaddr.map); ··· 489 489 } 490 490 err: 491 491 map__zput(he->ms.map); 492 - free(he->stat_acc); 492 + zfree(&he->stat_acc); 493 493 return -ENOMEM; 494 494 } 495 495 ··· 1254 1254 zfree(&he->stat_acc); 1255 1255 free_srcline(he->srcline); 1256 1256 if (he->srcfile && he->srcfile[0]) 1257 - free(he->srcfile); 1257 + zfree(&he->srcfile); 1258 1258 free_callchain(he->callchain); 1259 - free(he->trace_output); 1260 - free(he->raw_data); 1259 + zfree(&he->trace_output); 1260 + zfree(&he->raw_data); 1261 1261 ops->free(he); 1262 1262 } 1263 1263 ··· 2741 2741 2742 2742 list_for_each_entry_safe(node, tmp, &hists->hpp_formats, list) { 2743 2743 perf_hpp_list__for_each_format_safe(&node->hpp, fmt, pos) { 2744 - list_del(&fmt->list); 2744 + list_del_init(&fmt->list); 2745 2745 free(fmt); 2746 2746 } 2747 - list_del(&node->list); 2747 + list_del_init(&node->list); 2748 2748 free(node); 2749 2749 } 2750 2750 }
+3 -4
tools/perf/util/intel-bts.c
··· 12 12 #include <linux/types.h> 13 13 #include <linux/bitops.h> 14 14 #include <linux/log2.h> 15 + #include <linux/zalloc.h> 15 16 16 17 #include "cpumap.h" 17 18 #include "color.h" ··· 22 21 #include "map.h" 23 22 #include "symbol.h" 24 23 #include "session.h" 25 - #include "util.h" 26 24 #include "thread.h" 27 25 #include "thread-stack.h" 28 26 #include "debug.h" ··· 891 891 if (dump_trace) 892 892 return 0; 893 893 894 - if (session->itrace_synth_opts && session->itrace_synth_opts->set) { 894 + if (session->itrace_synth_opts->set) { 895 895 bts->synth_opts = *session->itrace_synth_opts; 896 896 } else { 897 897 itrace_synth_opts__set_default(&bts->synth_opts, 898 898 session->itrace_synth_opts->default_no_sample); 899 - if (session->itrace_synth_opts) 900 - bts->synth_opts.thread_stack = 899 + bts->synth_opts.thread_stack = 901 900 session->itrace_synth_opts->thread_stack; 902 901 } 903 902
+1 -1
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
··· 14 14 #include <stdint.h> 15 15 #include <inttypes.h> 16 16 #include <linux/compiler.h> 17 + #include <linux/zalloc.h> 17 18 18 19 #include "../cache.h" 19 - #include "../util.h" 20 20 #include "../auxtrace.h" 21 21 22 22 #include "intel-pt-insn-decoder.h"
+6 -9
tools/perf/util/intel-pt.c
··· 10 10 #include <errno.h> 11 11 #include <linux/kernel.h> 12 12 #include <linux/types.h> 13 + #include <linux/zalloc.h> 13 14 14 15 #include "../perf.h" 15 16 #include "session.h" ··· 23 22 #include "evsel.h" 24 23 #include "map.h" 25 24 #include "color.h" 26 - #include "util.h" 27 25 #include "thread.h" 28 26 #include "thread-stack.h" 29 27 #include "symbol.h" ··· 3210 3210 goto err_delete_thread; 3211 3211 } 3212 3212 3213 - if (session->itrace_synth_opts && session->itrace_synth_opts->set) { 3213 + if (session->itrace_synth_opts->set) { 3214 3214 pt->synth_opts = *session->itrace_synth_opts; 3215 3215 } else { 3216 3216 itrace_synth_opts__set_default(&pt->synth_opts, ··· 3220 3220 pt->synth_opts.branches = false; 3221 3221 pt->synth_opts.callchain = true; 3222 3222 } 3223 - if (session->itrace_synth_opts) 3224 - pt->synth_opts.thread_stack = 3223 + pt->synth_opts.thread_stack = 3225 3224 session->itrace_synth_opts->thread_stack; 3226 3225 } 3227 3226 ··· 3240 3241 pt->cbr2khz = tsc_freq / pt->max_non_turbo_ratio / 1000; 3241 3242 } 3242 3243 3243 - if (session->itrace_synth_opts) { 3244 - err = intel_pt_setup_time_ranges(pt, session->itrace_synth_opts); 3245 - if (err) 3246 - goto err_delete_thread; 3247 - } 3244 + err = intel_pt_setup_time_ranges(pt, session->itrace_synth_opts); 3245 + if (err) 3246 + goto err_delete_thread; 3248 3247 3249 3248 if (pt->synth_opts.calls) 3250 3249 pt->branches_filter |= PERF_IP_FLAG_CALL | PERF_IP_FLAG_ASYNC |
+3 -4
tools/perf/util/jitdump.c
··· 29 29 #include "../builtin.h" 30 30 31 31 #include <linux/ctype.h> 32 + #include <linux/zalloc.h> 32 33 33 34 struct jit_buf_desc { 34 35 struct perf_data *output; ··· 432 431 jd->unwinding_data, jd->eh_frame_hdr_size, jd->unwinding_size); 433 432 434 433 if (jd->debug_data && jd->nr_debug_entries) { 435 - free(jd->debug_data); 436 - jd->debug_data = NULL; 434 + zfree(&jd->debug_data); 437 435 jd->nr_debug_entries = 0; 438 436 } 439 437 440 438 if (jd->unwinding_data && jd->eh_frame_hdr_size) { 441 - free(jd->unwinding_data); 442 - jd->unwinding_data = NULL; 439 + zfree(&jd->unwinding_data); 443 440 jd->eh_frame_hdr_size = 0; 444 441 jd->unwinding_mapped_size = 0; 445 442 jd->unwinding_size = 0;
+2 -2
tools/perf/util/llvm-utils.c
··· 9 9 #include <stdio.h> 10 10 #include <stdlib.h> 11 11 #include <linux/err.h> 12 + #include <linux/zalloc.h> 12 13 #include "debug.h" 13 14 #include "llvm-utils.h" 14 15 #include "config.h" ··· 353 352 " \toption in [llvm] to \"\" to suppress this detection.\n\n", 354 353 *kbuild_dir); 355 354 356 - free(*kbuild_dir); 357 - *kbuild_dir = NULL; 355 + zfree(kbuild_dir); 358 356 goto errout; 359 357 } 360 358
+3 -3
tools/perf/util/machine.c
··· 15 15 #include "strlist.h" 16 16 #include "thread.h" 17 17 #include "vdso.h" 18 - #include "util.h" 19 18 #include <stdbool.h> 20 19 #include <sys/types.h> 21 20 #include <sys/stat.h> ··· 27 28 #include <linux/ctype.h> 28 29 #include <symbol/kallsyms.h> 29 30 #include <linux/mman.h> 31 + #include <linux/zalloc.h> 30 32 31 33 static void __machine__remove_thread(struct machine *machine, struct thread *th, bool lock); 32 34 ··· 810 810 out: 811 811 /* put the dso here, corresponding to machine__findnew_module_dso */ 812 812 dso__put(dso); 813 - free(m.name); 813 + zfree(&m.name); 814 814 return map; 815 815 } 816 816 ··· 1350 1350 if (m.kmod) 1351 1351 ret = map_groups__set_module_path(mg, path, &m); 1352 1352 1353 - free(m.name); 1353 + zfree(&m.name); 1354 1354 1355 1355 if (ret) 1356 1356 goto out;
+6 -3
tools/perf/util/map.c
··· 12 12 #include "thread.h" 13 13 #include "vdso.h" 14 14 #include "build-id.h" 15 - #include "util.h" 16 15 #include "debug.h" 17 16 #include "machine.h" 18 17 #include <linux/string.h> 18 + #include <linux/zalloc.h> 19 19 #include "srcline.h" 20 20 #include "namespaces.h" 21 21 #include "unwind.h" ··· 476 476 goto out_free_line; 477 477 478 478 ret = fprintf(fp, "|%-8d %.*s", line, len, srccode); 479 - state->srcfile = srcfile; 480 - state->line = line; 479 + 480 + if (state) { 481 + state->srcfile = srcfile; 482 + state->line = line; 483 + } 481 484 return ret; 482 485 483 486 out_free_line:
+1 -1
tools/perf/util/mem2node.c
··· 1 1 #include <errno.h> 2 2 #include <inttypes.h> 3 3 #include <linux/bitmap.h> 4 + #include <linux/zalloc.h> 4 5 #include "mem2node.h" 5 - #include "util.h" 6 6 7 7 struct phys_entry { 8 8 struct rb_node rb_node;
+6 -4
tools/perf/util/metricgroup.c
··· 18 18 #include "strlist.h" 19 19 #include <assert.h> 20 20 #include <linux/ctype.h> 21 + #include <linux/zalloc.h> 21 22 22 23 struct metric_event *metricgroup__lookup(struct rblist *metric_events, 23 24 struct perf_evsel *evsel, ··· 236 235 goto out_name; 237 236 return &me->nd; 238 237 out_name: 239 - free((char *)me->name); 238 + zfree(&me->name); 240 239 out_me: 241 240 free(me); 242 241 return NULL; ··· 264 263 struct mep *me = container_of(nd, struct mep, nd); 265 264 266 265 strlist__delete(me->metrics); 267 - free((void *)me->name); 266 + zfree(&me->name); 268 267 free(me); 269 268 } 270 269 ··· 490 489 491 490 list_for_each_entry_safe (eg, egtmp, group_list, nd) { 492 491 for (i = 0; i < eg->idnum; i++) 493 - free((char *)eg->ids[i]); 494 - free(eg->ids); 492 + zfree(&eg->ids[i]); 493 + zfree(&eg->ids); 494 + list_del_init(&eg->nd); 495 495 free(eg); 496 496 } 497 497 }
+1
tools/perf/util/mmap.c
··· 9 9 #include <sys/mman.h> 10 10 #include <inttypes.h> 11 11 #include <asm/bug.h> 12 + #include <linux/zalloc.h> 12 13 #ifdef HAVE_LIBNUMA_SUPPORT 13 14 #include <numaif.h> 14 15 #endif
+2 -1
tools/perf/util/namespaces.c
··· 5 5 */ 6 6 7 7 #include "namespaces.h" 8 - #include "util.h" 9 8 #include "event.h" 9 + #include "get_current_dir_name.h" 10 10 #include <sys/types.h> 11 11 #include <sys/stat.h> 12 12 #include <fcntl.h> ··· 17 17 #include <string.h> 18 18 #include <unistd.h> 19 19 #include <asm/bug.h> 20 + #include <linux/zalloc.h> 20 21 21 22 struct namespaces *namespaces__new(struct namespaces_event *event) 22 23 {
+4
tools/perf/util/namespaces.h
··· 13 13 #include <linux/refcount.h> 14 14 #include <linux/types.h> 15 15 16 + #ifndef HAVE_SETNS_SUPPORT 17 + int setns(int fd, int nstype); 18 + #endif 19 + 16 20 struct namespaces_event; 17 21 18 22 struct namespaces {
+3 -3
tools/perf/util/ordered-events.c
··· 138 138 139 139 if (!list_empty(cache)) { 140 140 new = list_entry(cache->next, struct ordered_event, list); 141 - list_del(&new->list); 141 + list_del_init(&new->list); 142 142 } else if (oe->buffer) { 143 143 new = &oe->buffer->event[oe->buffer_idx]; 144 144 if (++oe->buffer_idx == MAX_SAMPLE_BUFFER) ··· 394 394 * yet, we need to free only allocated ones ... 395 395 */ 396 396 if (oe->buffer) { 397 - list_del(&oe->buffer->list); 397 + list_del_init(&oe->buffer->list); 398 398 ordered_events_buffer__free(oe->buffer, oe->buffer_idx, oe); 399 399 } 400 400 401 401 /* ... and continue with the rest */ 402 402 list_for_each_entry_safe(buffer, tmp, &oe->to_free, list) { 403 - list_del(&buffer->list); 403 + list_del_init(&buffer->list); 404 404 ordered_events_buffer__free(buffer, MAX_SAMPLE_BUFFER, oe); 405 405 } 406 406 }
+1 -1
tools/perf/util/parse-branch-options.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include "perf.h" 3 - #include "util/util.h" 4 3 #include "util/debug.h" 5 4 #include <subcmd/parse-options.h> 6 5 #include "util/parse-branch-options.h" 6 + #include <stdlib.h> 7 7 8 8 #define BRANCH_OPT(n, m) \ 9 9 { .name = n, .mode = (m) }
+2 -1
tools/perf/util/parse-events.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include <linux/hw_breakpoint.h> 3 3 #include <linux/err.h> 4 + #include <linux/zalloc.h> 4 5 #include <dirent.h> 5 6 #include <errno.h> 6 7 #include <sys/ioctl.h> ··· 652 651 pr_debug("Failed to add BPF event %s:%s\n", 653 652 group, event); 654 653 list_for_each_entry_safe(evsel, tmp, &new_evsels, node) { 655 - list_del(&evsel->node); 654 + list_del_init(&evsel->node); 656 655 perf_evsel__delete(evsel); 657 656 } 658 657 return err;
-2
tools/perf/util/parse-events.y
··· 480 480 PE_BPF_OBJECT opt_event_config 481 481 { 482 482 struct parse_events_state *parse_state = _parse_state; 483 - struct parse_events_error *error = parse_state->error; 484 483 struct list_head *list; 485 484 486 485 ALLOC_LIST(list); ··· 625 626 PE_NAME array '=' PE_NAME 626 627 { 627 628 struct parse_events_term *term; 628 - int i; 629 629 630 630 ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, 631 631 $1, $4, &@1, &@4));
+6 -2
tools/perf/util/parse-regs-options.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 - #include "perf.h" 3 - #include "util/util.h" 2 + #include <stdbool.h> 3 + #include <stdlib.h> 4 + #include <stdint.h> 5 + #include <string.h> 6 + #include <stdio.h> 4 7 #include "util/debug.h" 5 8 #include <subcmd/parse-options.h> 9 + #include "util/perf_regs.h" 6 10 #include "util/parse-regs-options.h" 7 11 8 12 static int
+2 -2
tools/perf/util/pmu.c
··· 2 2 #include <linux/list.h> 3 3 #include <linux/compiler.h> 4 4 #include <linux/string.h> 5 + #include <linux/zalloc.h> 5 6 #include <sys/types.h> 6 7 #include <errno.h> 7 8 #include <fcntl.h> ··· 15 14 #include <api/fs/fs.h> 16 15 #include <locale.h> 17 16 #include <regex.h> 18 - #include "util.h" 19 17 #include "pmu.h" 20 18 #include "parse-events.h" 21 19 #include "cpumap.h" ··· 1245 1245 info->metric_expr = alias->metric_expr; 1246 1246 info->metric_name = alias->metric_name; 1247 1247 1248 - list_del(&term->list); 1248 + list_del_init(&term->list); 1249 1249 free(term); 1250 1250 } 1251 1251
+26 -29
tools/perf/util/probe-event.c
··· 19 19 #include <limits.h> 20 20 #include <elf.h> 21 21 22 - #include "util.h" 23 22 #include "event.h" 24 23 #include "namespaces.h" 25 24 #include "strlist.h" ··· 39 40 #include "string2.h" 40 41 41 42 #include <linux/ctype.h> 43 + #include <linux/zalloc.h> 42 44 43 45 #define PERFPROBE_GROUP "probe" 44 46 ··· 214 214 215 215 static void clear_perf_probe_point(struct perf_probe_point *pp) 216 216 { 217 - free(pp->file); 218 - free(pp->function); 219 - free(pp->lazy_line); 217 + zfree(&pp->file); 218 + zfree(&pp->function); 219 + zfree(&pp->lazy_line); 220 220 } 221 221 222 222 static void clear_probe_trace_events(struct probe_trace_event *tevs, int ntevs) ··· 1175 1175 1176 1176 void line_range__clear(struct line_range *lr) 1177 1177 { 1178 - free(lr->function); 1179 - free(lr->file); 1180 - free(lr->path); 1181 - free(lr->comp_dir); 1178 + zfree(&lr->function); 1179 + zfree(&lr->file); 1180 + zfree(&lr->path); 1181 + zfree(&lr->comp_dir); 1182 1182 intlist__delete(lr->line_list); 1183 - memset(lr, 0, sizeof(*lr)); 1184 1183 } 1185 1184 1186 1185 int line_range__init(struct line_range *lr) ··· 2202 2203 struct perf_probe_arg_field *field, *next; 2203 2204 int i; 2204 2205 2205 - free(pev->event); 2206 - free(pev->group); 2207 - free(pev->target); 2206 + zfree(&pev->event); 2207 + zfree(&pev->group); 2208 + zfree(&pev->target); 2208 2209 clear_perf_probe_point(&pev->point); 2209 2210 2210 2211 for (i = 0; i < pev->nargs; i++) { 2211 - free(pev->args[i].name); 2212 - free(pev->args[i].var); 2213 - free(pev->args[i].type); 2212 + zfree(&pev->args[i].name); 2213 + zfree(&pev->args[i].var); 2214 + zfree(&pev->args[i].type); 2214 2215 field = pev->args[i].field; 2215 2216 while (field) { 2216 2217 next = field->next; ··· 2219 2220 field = next; 2220 2221 } 2221 2222 } 2222 - free(pev->args); 2223 - memset(pev, 0, sizeof(*pev)); 2223 + zfree(&pev->args); 2224 2224 } 2225 2225 2226 2226 #define strdup_or_goto(str, label) \ ··· 2300 2302 struct probe_trace_arg_ref *ref, *next; 2301 2303 int i; 2302 2304 2303 - free(tev->event); 2304 - free(tev->group); 2305 - free(tev->point.symbol); 2306 - free(tev->point.realname); 2307 - free(tev->point.module); 2305 + zfree(&tev->event); 2306 + zfree(&tev->group); 2307 + zfree(&tev->point.symbol); 2308 + zfree(&tev->point.realname); 2309 + zfree(&tev->point.module); 2308 2310 for (i = 0; i < tev->nargs; i++) { 2309 - free(tev->args[i].name); 2310 - free(tev->args[i].value); 2311 - free(tev->args[i].type); 2311 + zfree(&tev->args[i].name); 2312 + zfree(&tev->args[i].value); 2313 + zfree(&tev->args[i].type); 2312 2314 ref = tev->args[i].ref; 2313 2315 while (ref) { 2314 2316 next = ref->next; ··· 2316 2318 ref = next; 2317 2319 } 2318 2320 } 2319 - free(tev->args); 2320 - memset(tev, 0, sizeof(*tev)); 2321 + zfree(&tev->args); 2321 2322 } 2322 2323 2323 2324 struct kprobe_blacklist_node { ··· 2333 2336 while (!list_empty(blacklist)) { 2334 2337 node = list_first_entry(blacklist, 2335 2338 struct kprobe_blacklist_node, list); 2336 - list_del(&node->list); 2337 - free(node->symbol); 2339 + list_del_init(&node->list); 2340 + zfree(&node->symbol); 2338 2341 free(node); 2339 2342 } 2340 2343 }
+1 -1
tools/perf/util/probe-file.c
··· 10 10 #include <sys/types.h> 11 11 #include <sys/uio.h> 12 12 #include <unistd.h> 13 + #include <linux/zalloc.h> 13 14 #include "namespaces.h" 14 - #include "util.h" 15 15 #include "event.h" 16 16 #include "strlist.h" 17 17 #include "strfilter.h"
+1 -1
tools/perf/util/probe-finder.c
··· 19 19 #include <dwarf-regs.h> 20 20 21 21 #include <linux/bitops.h> 22 + #include <linux/zalloc.h> 22 23 #include "event.h" 23 24 #include "dso.h" 24 25 #include "debug.h" 25 26 #include "intlist.h" 26 - #include "util.h" 27 27 #include "strlist.h" 28 28 #include "symbol.h" 29 29 #include "probe-finder.h"
+1 -1
tools/perf/util/pstack.c
··· 5 5 * (c) 2010 Arnaldo Carvalho de Melo <acme@redhat.com> 6 6 */ 7 7 8 - #include "util.h" 9 8 #include "pstack.h" 10 9 #include "debug.h" 11 10 #include <linux/kernel.h> 11 + #include <linux/zalloc.h> 12 12 #include <stdlib.h> 13 13 14 14 struct pstack {
+1
tools/perf/util/python-ext-sources
··· 18 18 ../lib/hweight.c 19 19 ../lib/string.c 20 20 ../lib/vsprintf.c 21 + ../lib/zalloc.c 21 22 util/thread_map.c 22 23 util/util.c 23 24 util/xyarray.c
+5 -6
tools/perf/util/s390-cpumsf.c
··· 146 146 #include <linux/types.h> 147 147 #include <linux/bitops.h> 148 148 #include <linux/log2.h> 149 + #include <linux/zalloc.h> 149 150 150 151 #include <sys/stat.h> 151 152 #include <sys/types.h> ··· 157 156 #include "evlist.h" 158 157 #include "machine.h" 159 158 #include "session.h" 160 - #include "util.h" 161 159 #include "thread.h" 162 160 #include "debug.h" 163 161 #include "auxtrace.h" ··· 756 756 */ 757 757 if (err) { 758 758 sfq->buffer = NULL; 759 - list_del(&buffer->list); 759 + list_del_init(&buffer->list); 760 760 auxtrace_buffer__free(buffer); 761 761 if (err > 0) /* Buffer done, no error */ 762 762 err = 0; ··· 1044 1044 auxtrace_heap__free(&sf->heap); 1045 1045 s390_cpumsf_free_queues(session); 1046 1046 session->auxtrace = NULL; 1047 - free(sf->logdir); 1047 + zfree(&sf->logdir); 1048 1048 free(sf); 1049 1049 } 1050 1050 ··· 1101 1101 if (rc == -1 || !S_ISDIR(stbuf.st_mode)) { 1102 1102 pr_err("Missing auxtrace log directory %s," 1103 1103 " continue with current directory...\n", value); 1104 - free(sf->logdir); 1105 - sf->logdir = NULL; 1104 + zfree(&sf->logdir); 1106 1105 } 1107 1106 return 1; 1108 1107 } ··· 1161 1162 auxtrace_queues__free(&sf->queues); 1162 1163 session->auxtrace = NULL; 1163 1164 err_free: 1164 - free(sf->logdir); 1165 + zfree(&sf->logdir); 1165 1166 free(sf); 1166 1167 return err; 1167 1168 }
+5 -2
tools/perf/util/session.c
··· 2 2 #include <errno.h> 3 3 #include <inttypes.h> 4 4 #include <linux/kernel.h> 5 + #include <linux/zalloc.h> 5 6 #include <traceevent/event-parse.h> 6 7 #include <api/fs/fs.h> 7 8 ··· 19 18 #include "session.h" 20 19 #include "tool.h" 21 20 #include "sort.h" 22 - #include "util.h" 23 21 #include "cpumap.h" 24 22 #include "perf_regs.h" 25 23 #include "asm/bug.h" ··· 1246 1246 return; 1247 1247 1248 1248 printf(": %d %d %s %" PRIu64 "\n", event->read.pid, event->read.tid, 1249 - evsel ? perf_evsel__name(evsel) : "FAIL", 1249 + perf_evsel__name(evsel), 1250 1250 event->read.value); 1251 + 1252 + if (!evsel) 1253 + return; 1251 1254 1252 1255 read_format = evsel->attr.read_format; 1253 1256
+3 -1
tools/perf/util/setns.c
··· 1 - #include "util.h" 1 + // SPDX-License-Identifier: LGPL-2.1 2 + 3 + #include "namespaces.h" 2 4 #include <unistd.h> 3 5 #include <sys/syscall.h> 4 6
+6 -5
tools/perf/util/srccode.c
··· 4 4 * Copyright (c) 2017, Intel Corporation. 5 5 * Author: Andi Kleen 6 6 */ 7 - #include "linux/list.h" 7 + #include <linux/list.h> 8 + #include <linux/zalloc.h> 8 9 #include <stdlib.h> 9 10 #include <sys/mman.h> 10 11 #include <sys/stat.h> ··· 83 82 84 83 static void free_srcfile(struct srcfile *sf) 85 84 { 86 - list_del(&sf->nd); 85 + list_del_init(&sf->nd); 87 86 hlist_del(&sf->hash_nd); 88 87 map_total_sz -= sf->maplen; 89 88 munmap(sf->map, sf->maplen); 90 - free(sf->lines); 91 - free(sf->fn); 89 + zfree(&sf->lines); 90 + zfree(&sf->fn); 92 91 free(sf); 93 92 num_srcfiles--; 94 93 } ··· 154 153 out_map: 155 154 munmap(h->map, sz); 156 155 out_fn: 157 - free(h->fn); 156 + zfree(&h->fn); 158 157 out_h: 159 158 free(h); 160 159 return NULL;
+1 -1
tools/perf/util/srcline.c
··· 6 6 7 7 #include <linux/kernel.h> 8 8 #include <linux/string.h> 9 + #include <linux/zalloc.h> 9 10 10 11 #include "util/dso.h" 11 - #include "util/util.h" 12 12 #include "util/debug.h" 13 13 #include "util/callchain.h" 14 14 #include "util/symbol_conf.h"
+2 -1
tools/perf/util/stat-shadow.c
··· 8 8 #include "evlist.h" 9 9 #include "expr.h" 10 10 #include "metricgroup.h" 11 + #include <linux/zalloc.h> 11 12 12 13 /* 13 14 * AGGR_GLOBAL: Use CPU 0 ··· 776 775 print_metric(config, ctxp, NULL, NULL, "", 0); 777 776 778 777 for (i = 1; i < pctx.num_ids; i++) 779 - free((void *)pctx.ids[i].name); 778 + zfree(&pctx.ids[i].name); 780 779 } 781 780 782 781 void perf_stat__print_shadow_stats(struct perf_stat_config *config,
+2 -1
tools/perf/util/stat.c
··· 6 6 #include "evlist.h" 7 7 #include "evsel.h" 8 8 #include "thread_map.h" 9 + #include <linux/zalloc.h> 9 10 10 11 void update_stats(struct stats *stats, u64 val) 11 12 { ··· 133 132 struct perf_stat_evsel *ps = evsel->stats; 134 133 135 134 if (ps) 136 - free(ps->group_data); 135 + zfree(&ps->group_data); 137 136 zfree(&evsel->stats); 138 137 } 139 138
+2 -1
tools/perf/util/strbuf.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include "debug.h" 3 - #include "util.h" 4 3 #include <linux/kernel.h> 4 + #include <linux/zalloc.h> 5 5 #include <errno.h> 6 + #include <stdlib.h> 6 7 7 8 /* 8 9 * Used as the default ->buf value, so that people can always assume
+2 -1
tools/perf/util/strfilter.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 - #include "util.h" 3 2 #include "string2.h" 4 3 #include "strfilter.h" 5 4 6 5 #include <errno.h> 6 + #include <stdlib.h> 7 7 #include <linux/ctype.h> 8 8 #include <linux/string.h> 9 + #include <linux/zalloc.h> 9 10 10 11 /* Operators */ 11 12 static const char *OP_and = "&"; /* Logical AND */
+1 -1
tools/perf/util/strlist.c
··· 4 4 */ 5 5 6 6 #include "strlist.h" 7 - #include "util.h" 8 7 #include <errno.h> 9 8 #include <stdio.h> 10 9 #include <stdlib.h> 11 10 #include <string.h> 12 11 #include <unistd.h> 12 + #include <linux/zalloc.h> 13 13 14 14 static 15 15 struct rb_node *strlist__node_new(struct rblist *rblist, const void *entry)
+1 -1
tools/perf/util/svghelper.c
··· 15 15 #include <string.h> 16 16 #include <linux/bitmap.h> 17 17 #include <linux/time64.h> 18 + #include <linux/zalloc.h> 18 19 19 20 #include "perf.h" 20 21 #include "svghelper.h" 21 - #include "util.h" 22 22 #include "cpumap.h" 23 23 24 24 static u64 first_time, last_time;
+10 -8
tools/perf/util/symbol-elf.c
··· 2 2 #include <fcntl.h> 3 3 #include <stdio.h> 4 4 #include <errno.h> 5 + #include <stdlib.h> 5 6 #include <string.h> 6 7 #include <unistd.h> 7 8 #include <inttypes.h> ··· 17 16 #include "debug.h" 18 17 #include "util.h" 19 18 #include <linux/ctype.h> 19 + #include <linux/zalloc.h> 20 20 #include <symbol/kallsyms.h> 21 21 22 22 #ifndef EM_AARCH64 ··· 1478 1476 struct phdr_data *p, *tmp; 1479 1477 1480 1478 list_for_each_entry_safe(p, tmp, &kci->phdrs, node) { 1481 - list_del(&p->node); 1479 + list_del_init(&p->node); 1482 1480 free(p); 1483 1481 } 1484 1482 } ··· 1501 1499 struct sym_data *s, *tmp; 1502 1500 1503 1501 list_for_each_entry_safe(s, tmp, &kci->syms, node) { 1504 - list_del(&s->node); 1502 + list_del_init(&s->node); 1505 1503 free(s); 1506 1504 } 1507 1505 } ··· 2133 2131 return 0; 2134 2132 2135 2133 out_free_args: 2136 - free(tmp->args); 2134 + zfree(&tmp->args); 2137 2135 out_free_name: 2138 - free(tmp->name); 2136 + zfree(&tmp->name); 2139 2137 out_free_prov: 2140 - free(tmp->provider); 2138 + zfree(&tmp->provider); 2141 2139 out_free_note: 2142 2140 free(tmp); 2143 2141 out_err: ··· 2252 2250 int nr_free = 0; 2253 2251 2254 2252 list_for_each_entry_safe(pos, tmp, sdt_notes, note_list) { 2255 - list_del(&pos->note_list); 2256 - free(pos->name); 2257 - free(pos->provider); 2253 + list_del_init(&pos->note_list); 2254 + zfree(&pos->name); 2255 + zfree(&pos->provider); 2258 2256 free(pos); 2259 2257 nr_free++; 2260 2258 }
+2 -1
tools/perf/util/symbol-minimal.c
··· 7 7 #include <stdio.h> 8 8 #include <fcntl.h> 9 9 #include <string.h> 10 + #include <stdlib.h> 10 11 #include <byteswap.h> 11 12 #include <sys/stat.h> 12 - 13 + #include <linux/zalloc.h> 13 14 14 15 static bool check_need_swap(int file_endian) 15 16 {
+1
tools/perf/util/symbol.c
··· 26 26 #include "header.h" 27 27 #include "path.h" 28 28 #include <linux/ctype.h> 29 + #include <linux/zalloc.h> 29 30 30 31 #include <elf.h> 31 32 #include <limits.h>
+1 -1
tools/perf/util/syscalltbl.c
··· 10 10 #include <linux/compiler.h> 11 11 12 12 #ifdef HAVE_SYSCALL_TABLE_SUPPORT 13 + #include <linux/zalloc.h> 13 14 #include <string.h> 14 15 #include "string2.h" 15 - #include "util.h" 16 16 17 17 #if defined(__x86_64__) 18 18 #include <asm/syscalls_64.c>
+1 -1
tools/perf/util/target.c
··· 10 10 #include "debug.h" 11 11 12 12 #include <pwd.h> 13 + #include <stdlib.h> 13 14 #include <string.h> 14 - 15 15 16 16 enum target_errno target__validate(struct target *target) 17 17 {
+2 -1
tools/perf/util/thread-stack.c
··· 7 7 #include <linux/rbtree.h> 8 8 #include <linux/list.h> 9 9 #include <linux/log2.h> 10 + #include <linux/zalloc.h> 10 11 #include <errno.h> 12 + #include <stdlib.h> 11 13 #include "thread.h" 12 14 #include "event.h" 13 15 #include "machine.h" 14 16 #include "env.h" 15 - #include "util.h" 16 17 #include "debug.h" 17 18 #include "symbol.h" 18 19 #include "comm.h"
+3 -3
tools/perf/util/thread.c
··· 5 5 #include <stdio.h> 6 6 #include <string.h> 7 7 #include <linux/kernel.h> 8 + #include <linux/zalloc.h> 8 9 #include "session.h" 9 10 #include "thread.h" 10 11 #include "thread-stack.h" 11 - #include "util.h" 12 12 #include "debug.h" 13 13 #include "namespaces.h" 14 14 #include "comm.h" ··· 93 93 down_write(&thread->namespaces_lock); 94 94 list_for_each_entry_safe(namespaces, tmp_namespaces, 95 95 &thread->namespaces_list, list) { 96 - list_del(&namespaces->list); 96 + list_del_init(&namespaces->list); 97 97 namespaces__free(namespaces); 98 98 } 99 99 up_write(&thread->namespaces_lock); 100 100 101 101 down_write(&thread->comm_lock); 102 102 list_for_each_entry_safe(comm, tmp_comm, &thread->comm_list, list) { 103 - list_del(&comm->list); 103 + list_del_init(&comm->list); 104 104 comm__free(comm); 105 105 } 106 106 up_write(&thread->comm_lock);
+2 -2
tools/perf/util/thread_map.c
··· 13 13 #include <string.h> 14 14 #include <api/fs/fs.h> 15 15 #include <linux/string.h> 16 + #include <linux/zalloc.h> 16 17 #include "asm/bug.h" 17 18 #include "thread_map.h" 18 - #include "util.h" 19 19 #include "debug.h" 20 20 #include "event.h" 21 21 ··· 480 480 /* 481 481 * Free the 'idx' item and shift the rest up. 482 482 */ 483 - free(threads->map[idx].comm); 483 + zfree(&threads->map[idx].comm); 484 484 485 485 for (i = idx; i < threads->nr - 1; i++) 486 486 threads->map[i] = threads->map[i + 1];
+1
tools/perf/util/trace-event-info.c
··· 18 18 #include <stdbool.h> 19 19 #include <linux/list.h> 20 20 #include <linux/kernel.h> 21 + #include <linux/zalloc.h> 21 22 22 23 #include "../perf.h" 23 24 #include "trace-event.h"
+1 -1
tools/perf/util/trace-event-scripting.c
··· 12 12 13 13 #include "../perf.h" 14 14 #include "debug.h" 15 - #include "util.h" 16 15 #include "trace-event.h" 16 + #include <linux/zalloc.h> 17 17 18 18 struct scripting_context *scripting_context; 19 19
+1
tools/perf/util/unwind-libdw.c
··· 12 12 #include "symbol.h" 13 13 #include "thread.h" 14 14 #include <linux/types.h> 15 + #include <linux/zalloc.h> 15 16 #include "event.h" 16 17 #include "perf_regs.h" 17 18 #include "callchain.h"
+2 -1
tools/perf/util/unwind-libunwind-local.c
··· 25 25 #include <unistd.h> 26 26 #include <sys/mman.h> 27 27 #include <linux/list.h> 28 + #include <linux/zalloc.h> 28 29 #ifndef REMOTE_UNWIND_LIBUNWIND 29 30 #include <libunwind.h> 30 31 #include <libunwind-ptrace.h> ··· 346 345 __func__, 347 346 dso->symsrc_filename, 348 347 debuglink); 349 - free(dso->symsrc_filename); 348 + zfree(&dso->symsrc_filename); 350 349 } 351 350 dso->symsrc_filename = debuglink; 352 351 } else {
+3
tools/perf/util/usage.c
··· 9 9 */ 10 10 #include "util.h" 11 11 #include "debug.h" 12 + #include <stdio.h> 13 + #include <stdlib.h> 14 + #include <linux/compiler.h> 12 15 13 16 static __noreturn void usage_builtin(const char *err) 14 17 {
-17
tools/perf/util/util.h
··· 9 9 #include <fcntl.h> 10 10 #include <stdbool.h> 11 11 #include <stddef.h> 12 - #include <stdlib.h> 13 - #include <stdarg.h> 14 12 #include <linux/compiler.h> 15 13 #include <sys/types.h> 16 14 17 15 /* General helper functions */ 18 16 void usage(const char *err) __noreturn; 19 17 void die(const char *err, ...) __noreturn __printf(1, 2); 20 - 21 - static inline void *zalloc(size_t size) 22 - { 23 - return calloc(1, size); 24 - } 25 - 26 - #define zfree(ptr) ({ free(*ptr); *ptr = NULL; }) 27 18 28 19 struct dirent; 29 20 struct nsinfo; ··· 50 59 51 60 const char *perf_tip(const char *dirpath); 52 61 53 - #ifndef HAVE_GET_CURRENT_DIR_NAME 54 - char *get_current_dir_name(void); 55 - #endif 56 - 57 62 #ifndef HAVE_SCHED_GETCPU_SUPPORT 58 63 int sched_getcpu(void); 59 - #endif 60 - 61 - #ifndef HAVE_SETNS_SUPPORT 62 - int setns(int fd, int nstype); 63 64 #endif 64 65 65 66 extern bool perf_singlethreaded;
+1 -1
tools/perf/util/values.c
··· 3 3 #include <stdio.h> 4 4 #include <stdlib.h> 5 5 #include <errno.h> 6 + #include <linux/zalloc.h> 6 7 7 - #include "util.h" 8 8 #include "values.h" 9 9 #include "debug.h" 10 10
+1
tools/perf/util/vdso.c
··· 16 16 #include "machine.h" 17 17 #include "thread.h" 18 18 #include "linux/string.h" 19 + #include <linux/zalloc.h> 19 20 #include "debug.h" 20 21 21 22 /*
+1 -1
tools/perf/util/xyarray.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include "xyarray.h" 3 - #include "util.h" 4 3 #include <stdlib.h> 5 4 #include <string.h> 5 + #include <linux/zalloc.h> 6 6 7 7 struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size) 8 8 {