Commit f50b8357 authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo

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: default avatarIan 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.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 7a3fb8b5
...@@ -86,17 +86,16 @@ static struct parse_events_term test_terms[] = { ...@@ -86,17 +86,16 @@ static struct parse_events_term test_terms[] = {
* Prepare format directory data, exported by kernel * Prepare format directory data, exported by kernel
* at /sys/bus/event_source/devices/<dev>/format. * at /sys/bus/event_source/devices/<dev>/format.
*/ */
static char *test_format_dir_get(void) static char *test_format_dir_get(char *dir, size_t sz)
{ {
static char dir[PATH_MAX];
unsigned int i; unsigned int i;
snprintf(dir, PATH_MAX, "/tmp/perf-pmu-test-format-XXXXXX"); snprintf(dir, sz, "/tmp/perf-pmu-test-format-XXXXXX");
if (!mkdtemp(dir)) if (!mkdtemp(dir))
return NULL; return NULL;
for (i = 0; i < ARRAY_SIZE(test_formats); i++) { for (i = 0; i < ARRAY_SIZE(test_formats); i++) {
static char name[PATH_MAX]; char name[PATH_MAX];
struct test_format *format = &test_formats[i]; struct test_format *format = &test_formats[i];
FILE *file; FILE *file;
...@@ -118,12 +117,13 @@ static char *test_format_dir_get(void) ...@@ -118,12 +117,13 @@ static char *test_format_dir_get(void)
/* Cleanup format directory. */ /* Cleanup format directory. */
static int test_format_dir_put(char *dir) static int test_format_dir_put(char *dir)
{ {
char buf[PATH_MAX]; char buf[PATH_MAX + 20];
snprintf(buf, PATH_MAX, "rm -f %s/*\n", dir);
snprintf(buf, sizeof(buf), "rm -f %s/*\n", dir);
if (system(buf)) if (system(buf))
return -1; return -1;
snprintf(buf, PATH_MAX, "rmdir %s\n", dir); snprintf(buf, sizeof(buf), "rmdir %s\n", dir);
return system(buf); return system(buf);
} }
...@@ -140,7 +140,8 @@ static struct list_head *test_terms_list(void) ...@@ -140,7 +140,8 @@ static struct list_head *test_terms_list(void)
static int test__pmu(struct test_suite *test __maybe_unused, int subtest __maybe_unused) static int test__pmu(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
{ {
char *format = test_format_dir_get(); char dir[PATH_MAX];
char *format = test_format_dir_get(dir, sizeof(dir));
LIST_HEAD(formats); LIST_HEAD(formats);
struct list_head *terms = test_terms_list(); struct list_head *terms = test_terms_list();
int ret; int ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment