Skip to content

Commit f50b835

Browse files
captain5050acmel
authored andcommitted
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>
1 parent 7a3fb8b commit f50b835

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

tools/perf/tests/pmu.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,16 @@ static struct parse_events_term test_terms[] = {
8686
* Prepare format directory data, exported by kernel
8787
* at /sys/bus/event_source/devices/<dev>/format.
8888
*/
89-
static char *test_format_dir_get(void)
89+
static char *test_format_dir_get(char *dir, size_t sz)
9090
{
91-
static char dir[PATH_MAX];
9291
unsigned int i;
9392

94-
snprintf(dir, PATH_MAX, "/tmp/perf-pmu-test-format-XXXXXX");
93+
snprintf(dir, sz, "/tmp/perf-pmu-test-format-XXXXXX");
9594
if (!mkdtemp(dir))
9695
return NULL;
9796

9897
for (i = 0; i < ARRAY_SIZE(test_formats); i++) {
99-
static char name[PATH_MAX];
98+
char name[PATH_MAX];
10099
struct test_format *format = &test_formats[i];
101100
FILE *file;
102101

@@ -118,12 +117,13 @@ static char *test_format_dir_get(void)
118117
/* Cleanup format directory. */
119118
static int test_format_dir_put(char *dir)
120119
{
121-
char buf[PATH_MAX];
122-
snprintf(buf, PATH_MAX, "rm -f %s/*\n", dir);
120+
char buf[PATH_MAX + 20];
121+
122+
snprintf(buf, sizeof(buf), "rm -f %s/*\n", dir);
123123
if (system(buf))
124124
return -1;
125125

126-
snprintf(buf, PATH_MAX, "rmdir %s\n", dir);
126+
snprintf(buf, sizeof(buf), "rmdir %s\n", dir);
127127
return system(buf);
128128
}
129129

@@ -140,7 +140,8 @@ static struct list_head *test_terms_list(void)
140140

141141
static int test__pmu(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
142142
{
143-
char *format = test_format_dir_get();
143+
char dir[PATH_MAX];
144+
char *format = test_format_dir_get(dir, sizeof(dir));
144145
LIST_HEAD(formats);
145146
struct list_head *terms = test_terms_list();
146147
int ret;

0 commit comments

Comments
 (0)