Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Namhyung Kim" <namhyung@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2 4/6] perf kvm: Do not copy filename string
Date: Tue, 23 Jun 2026 21:46:55 +0000	[thread overview]
Message-ID: <20260623214655.E522E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260623191439.3621593-5-namhyung@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The error checking logic for `get_filename_for_perf_kvm()` is unreachable dead code.
--

commit 0b8de0bac81d07f5d9beff7d22b8144187910bab
Author: Namhyung Kim <namhyung@kernel.org>

perf kvm: Do not copy filename string

As it removed STRDUP_FAIL_EXIT(), it no longer calls free() for elements
in the copied argv.  Thus, the filename should not be allocated as well.
In fact, it's a pointer to string literals and should be fine to pass
the pointer.

> diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
> index 278543ca66a37..021af3c64acd0 100644
> --- a/tools/perf/builtin-kvm.c
> +++ b/tools/perf/builtin-kvm.c
> @@ -607,11 +607,11 @@ static const char *get_filename_for_perf_kvm(void)
>  	const char *filename;
>  
>  	if (perf_host && !perf_guest)
> -		filename = strdup("perf.data.host");
> +		filename = "perf.data.host";
>  	else if (!perf_host && perf_guest)
> -		filename = strdup("perf.data.guest");
> +		filename = "perf.data.guest";
>  	else
> -		filename = strdup("perf.data.kvm");
> +		filename = "perf.data.kvm";
>  
>  	return filename;
>  }

[Severity: Low]
Does this change leave unreachable dead code in cmd_kvm()?

Now that get_filename_for_perf_kvm() returns static string literals, it can
never return NULL. However, its caller cmd_kvm() still checks for NULL and
returns -ENOMEM:

	if (!file_name) {
		file_name = get_filename_for_perf_kvm();

		if (!file_name) {
			pr_err("Failed to allocate memory for filename\n");
			return -ENOMEM;
		}
	}

Is it okay to clean up the redundant NULL check and error message from
cmd_kvm() since this allocation failure is no longer possible?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260623191439.3621593-1-namhyung@kernel.org?part=4

  reply	other threads:[~2026-06-23 21:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-23 19:14 [PATCH v2 0/6] perf kvm: A small update in the default arch event Namhyung Kim
2026-06-23 19:14 ` [PATCH v2 1/6] perf kvm: Factor out kvm_need_default_arch_event() Namhyung Kim
2026-06-23 21:20   ` sashiko-bot
2026-06-23 19:14 ` [PATCH v2 2/6] perf kvm: Check kvm_need_default_arch_event() early Namhyung Kim
2026-06-23 19:14 ` [PATCH v2 3/6] perf kvm: Kill STRDUP_FAIL_EXIT() Namhyung Kim
2026-06-23 19:14 ` [PATCH v2 4/6] perf kvm: Do not copy filename string Namhyung Kim
2026-06-23 21:46   ` sashiko-bot [this message]
2026-06-23 19:14 ` [PATCH v2 5/6] perf kvm: Fix a memory leak in the usage string Namhyung Kim
2026-06-23 19:14 ` [PATCH v2 6/6] perf test: Simplify perf kvm record/report tests Namhyung Kim
2026-06-23 21:57   ` sashiko-bot

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=20260623214655.E522E1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=namhyung@kernel.org \
    --cc=sashiko-reviews@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