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

Configure Feed

Select the types of activity you want to include in your feed.

perf test pmu: Avoid 2 static path arrays

Avoid two static paths that contributed 8,192 bytes to .bss are only
used duing the perf parse pmu test. This change helps FORTIFY
triggering 2 warnings like:

```
tests/pmu.c: In function ‘test__pmu’:
tests/pmu.c:121:43: error: ‘%s’ directive output may be truncated writing up to 4095 bytes into a region of size 4090 [-Werror=format-truncation=]
121 | snprintf(buf, sizeof(buf), "rm -f %s/*\n", dir);
```

So make buf a little larger.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Ross Zwisler <zwisler@chromium.org>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
Cc: Yang Jihong <yangjihong1@huawei.com>
Link: https://lore.kernel.org/r/20230526183401.2326121-16-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
f50b8357 7a3fb8b5

+9 -8
+9 -8
tools/perf/tests/pmu.c
··· 86 86 * Prepare format directory data, exported by kernel 87 87 * at /sys/bus/event_source/devices/<dev>/format. 88 88 */ 89 - static char *test_format_dir_get(void) 89 + static char *test_format_dir_get(char *dir, size_t sz) 90 90 { 91 - static char dir[PATH_MAX]; 92 91 unsigned int i; 93 92 94 - snprintf(dir, PATH_MAX, "/tmp/perf-pmu-test-format-XXXXXX"); 93 + snprintf(dir, sz, "/tmp/perf-pmu-test-format-XXXXXX"); 95 94 if (!mkdtemp(dir)) 96 95 return NULL; 97 96 98 97 for (i = 0; i < ARRAY_SIZE(test_formats); i++) { 99 - static char name[PATH_MAX]; 98 + char name[PATH_MAX]; 100 99 struct test_format *format = &test_formats[i]; 101 100 FILE *file; 102 101 ··· 117 118 /* Cleanup format directory. */ 118 119 static int test_format_dir_put(char *dir) 119 120 { 120 - char buf[PATH_MAX]; 121 - snprintf(buf, PATH_MAX, "rm -f %s/*\n", dir); 121 + char buf[PATH_MAX + 20]; 122 + 123 + snprintf(buf, sizeof(buf), "rm -f %s/*\n", dir); 122 124 if (system(buf)) 123 125 return -1; 124 126 125 - snprintf(buf, PATH_MAX, "rmdir %s\n", dir); 127 + snprintf(buf, sizeof(buf), "rmdir %s\n", dir); 126 128 return system(buf); 127 129 } 128 130 ··· 140 140 141 141 static int test__pmu(struct test_suite *test __maybe_unused, int subtest __maybe_unused) 142 142 { 143 - char *format = test_format_dir_get(); 143 + char dir[PATH_MAX]; 144 + char *format = test_format_dir_get(dir, sizeof(dir)); 144 145 LIST_HEAD(formats); 145 146 struct list_head *terms = test_terms_list(); 146 147 int ret;