public inbox for linux-perf-users@vger.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jakub Brnak" <jbrnak@redhat.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v7 5/7] perf test: Format log directories for shell tests
Date: Thu, 16 Apr 2026 18:56:16 +0000	[thread overview]
Message-ID: <20260416185616.D15AFC2BCAF@smtp.kernel.org> (raw)
In-Reply-To: <20260416111419.385010-6-jbrnak@redhat.com>

Sashiko AI review found 2 potential issue(s):
- [Medium] Temporary directory resource leak when strdup() fails.
- [Low] Implementation of character replacement is overly aggressive and misaligned with the commit intent.
--

commit deaef0503b790e27361344881ded63d280631c12
Author: Jakub Brnak <jbrnak@redhat.com>

perf test: Format log directories for shell tests

This commit creates a temporary directory for shell tests using a template based
on the test suite name. It replaces non-alphanumeric characters with underscores
to avoid issues with whitespace or special characters when logging.

>     Replace the whitespace characters with an underscore to prevent the
>     possible issues caused by the name splitting.

This isn't a bug, but the commit message mentions replacing whitespace
characters, while the implementation replaces all non-alphanumeric characters.
Could the commit message be updated to match the code?

> diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
> index 306ecfe5e22ff..6cdff3687a828 100644
> --- a/tools/perf/tests/builtin-test.c
> +++ b/tools/perf/tests/builtin-test.c
[ ... ]
> @@ -342,16 +342,28 @@ static bool create_logs(struct test_suite *t, int pass)
>  	return false;
>  }
>  
> +static const char PERF_LOG_PREFIX[] = "/tmp/perf_test_";
> +static const char PERF_LOG_SUFFIX[] = ".XXXXXX";
> +
>  static char *setup_shell_logs(const char *name)
>  {
>  	char template[PATH_MAX];
>  	char *temp_dir;
> +	size_t i, len;
>  
> -	if (snprintf(template, PATH_MAX, "/tmp/perf_test_%s.XXXXXX", name) >= PATH_MAX) {
> +	if (snprintf(template, PATH_MAX, "%s%s%s", PERF_LOG_PREFIX, name,
> +		     PERF_LOG_SUFFIX) >= PATH_MAX) {
>  		pr_err("Failed to create log dir template");
>  		return NULL; /* Skip the testsuite */
>  	}
>  
> +	/* Replace non-alphanumeric characters with _ in the name part */
> +	len = strlen(template);
> +	for (i = sizeof(PERF_LOG_PREFIX) - 1; i < len - (sizeof(PERF_LOG_SUFFIX) - 1); i++) {
> +		if (!isalnum((unsigned char)template[i]))
> +			template[i] = '_';
> +	}
> +
>  	temp_dir = mkdtemp(template);
>  	if (temp_dir) {
>  		setenv("PERFSUITE_RUN_DIR", temp_dir, 1);

If strdup(temp_dir) fails right after this and returns NULL, do we leave the
newly created temporary directory on the filesystem? 

It looks like mkdtemp() creates the directory, but there is no cleanup if the
memory allocation fails. Additionally, should we unset the PERFSUITE_RUN_DIR
environment variable on this error path?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260416111419.385010-1-jbrnak@redhat.com?part=5

  reply	other threads:[~2026-04-16 18:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-16 11:14 [PATCH v7 0/7] Introduce structure for shell tests Jakub Brnak
2026-04-16 11:14 ` [PATCH v7 1/7] perf tests: Create a " Jakub Brnak
2026-04-16 11:38   ` sashiko-bot
2026-04-16 11:14 ` [PATCH v7 2/7] perf test: Provide setup for the shell test suite Jakub Brnak
2026-04-16 12:07   ` sashiko-bot
2026-04-16 11:14 ` [PATCH v7 3/7] perf test: Add empty setup for base_probe Jakub Brnak
2026-04-16 11:14 ` [PATCH v7 4/7] perf test: Introduce storing logs for shell tests Jakub Brnak
2026-04-16 18:30   ` sashiko-bot
2026-04-16 11:14 ` [PATCH v7 5/7] perf test: Format log directories " Jakub Brnak
2026-04-16 18:56   ` sashiko-bot [this message]
2026-04-16 11:14 ` [PATCH v7 6/7] perf test: Remove perftool drivers Jakub Brnak
2026-04-16 19:08   ` sashiko-bot
2026-04-16 11:14 ` [PATCH v7 7/7] perf test: Fix relative path for 'stderr-whitelist.txt' Jakub Brnak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260416185616.D15AFC2BCAF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=jbrnak@redhat.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox