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>
This commit is contained in:
Ian Rogers 2023-05-26 11:34:00 -07:00 committed by Arnaldo Carvalho de Melo
parent 7a3fb8b5c4
commit f50b8357f8
1 changed files with 9 additions and 8 deletions

View File

@ -86,17 +86,16 @@ static struct parse_events_term test_terms[] = {
* Prepare format directory data, exported by kernel
* 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;
snprintf(dir, PATH_MAX, "/tmp/perf-pmu-test-format-XXXXXX");
snprintf(dir, sz, "/tmp/perf-pmu-test-format-XXXXXX");
if (!mkdtemp(dir))
return NULL;
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];
FILE *file;
@ -118,12 +117,13 @@ static char *test_format_dir_get(void)
/* Cleanup format directory. */
static int test_format_dir_put(char *dir)
{
char buf[PATH_MAX];
snprintf(buf, PATH_MAX, "rm -f %s/*\n", dir);
char buf[PATH_MAX + 20];
snprintf(buf, sizeof(buf), "rm -f %s/*\n", dir);
if (system(buf))
return -1;
snprintf(buf, PATH_MAX, "rmdir %s\n", dir);
snprintf(buf, sizeof(buf), "rmdir %s\n", dir);
return system(buf);
}
@ -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)
{
char *format = test_format_dir_get();
char dir[PATH_MAX];
char *format = test_format_dir_get(dir, sizeof(dir));
LIST_HEAD(formats);
struct list_head *terms = test_terms_list();
int ret;