Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Thomas Falcon" <thomas.falcon@intel.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v6 3/6] perf header: Support memory ranges
Date: Mon, 31 Aug 2026 22:12:57 +0000	[thread overview]
Message-ID: <20260831221257.9EE4D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260831204613.2793526-4-thomas.falcon@intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Memory leak of `env->memory_ranges` when processing multiple HEADER_MEMORY_RANGES sections.
--

commit 0dcf161b1003085435ecec4dd99b1a0326a98d1b
Author: Thomas Falcon <thomas.falcon@intel.com>

perf header: Support memory ranges

This patch introduces support for parsing and storing memory ranges from
the ACPI MRRM table in perf.data files. It adds a new feature bit,
HEADER_MEMORY_RANGES, and exposes the data via the perf-report and
perf-script tools. The data is read directly from sysfs and parsed
during feature initialization.

Link: https://lore.kernel.org/lkml/20250505173819.419271-1-tony.luck@intel.com/

> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index 7db7da090a1e0..83416ce395d7c 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
[ ... ]
> @@ -4202,6 +4346,64 @@ static int process_cpu_domain_info(struct feat_fd *ff, void *data __maybe_unused
>  	return ret;
>  }
>  
> +static int process_memory_ranges(struct feat_fd *ff, void *data __maybe_unused)
> +{
> +	struct perf_env *env = &ff->ph->env;
> +	struct memory_range *ranges, *r;
> +	u32 nr_memory_ranges, i;
> +
> +	if (do_read_u32(ff, &nr_memory_ranges))
> +		return -1;
> +
> +	if (!nr_memory_ranges) {
> +		pr_debug("memory ranges not available\n");
> +		return 0;
> +	}
> +
[ ... ]
> +	ranges = calloc(nr_memory_ranges, sizeof(*ranges));
> +	if (!ranges)
> +		return -1;
> +
> +	for (i = 0; i < nr_memory_ranges; i++) {
> +		r = &ranges[i];
> +
> +		if (do_read_u64(ff, &r->base))
> +			goto error;
> +		if (do_read_u64(ff, &r->length))
> +			goto error;
> +		if (do_read_u32(ff, (u32 *) &r->node))
> +			goto error;
> +		if (__do_read(ff, &r->local_region_id, sizeof(u8)))
> +			goto error;
> +		if (__do_read(ff, &r->remote_region_id, sizeof(u8)))
> +			goto error;
> +	}
> +
> +	env->memory_ranges = ranges;
> +	env->nr_memory_ranges = nr_memory_ranges;
> +
> +	return 0;

[Severity: Medium]
In pipe mode, a perf.data stream containing multiple HEADER_MEMORY_RANGES
feature events can cause process_memory_ranges() to be executed multiple
times.

When this occurs, does this assignment leak the previously allocated
env->memory_ranges array, since the newly allocated ranges array
unconditionally overwrites it without first freeing the prior allocation?

> +error:
> +	zfree(&ranges);
> +	return -1;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260831204613.2793526-1-thomas.falcon@intel.com?part=3

  reply	other threads:[~2026-08-31 22:12 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 20:46 [PATCH v6 0/6] perf: Add support for memory region/range reporting Thomas Falcon
2026-08-31 20:46 ` [PATCH v6 1/6] perf mem: Fix size tracking for mem_lvl's in perf_script__meminfo_scnprintf() Thomas Falcon
2026-08-31 21:55   ` sashiko-bot
2026-08-31 20:46 ` [PATCH v6 2/6] perf mem: Add support for printing PERF_MEM_LVLNUM_L0 Thomas Falcon
2026-08-31 22:01   ` sashiko-bot
2026-08-31 20:46 ` [PATCH v6 3/6] perf header: Support memory ranges Thomas Falcon
2026-08-31 22:12   ` sashiko-bot [this message]
2026-08-31 20:46 ` [PATCH v6 4/6] perf tools: Show memory region in perf-c2c subcommand Thomas Falcon
2026-08-31 22:20   ` sashiko-bot
2026-08-31 20:46 ` [PATCH v6 5/6] perf tools: Show memory region in perf-script subcommand Thomas Falcon
2026-08-31 22:32   ` sashiko-bot
2026-08-31 20:46 ` [PATCH v6 6/6] perf c2c: print memory region data with stdio output Thomas Falcon
2026-08-31 22:44   ` 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=20260831221257.9EE4D1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=thomas.falcon@intel.com \
    /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