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 v7 3/6] perf header: Support memory ranges
Date: Wed, 09 Sep 2026 16:15:35 +0000	[thread overview]
Message-ID: <20260909161536.294031F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260909160218.174928-4-thomas.falcon@intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Potential memory leak of `env->memory_ranges` in `process_memory_ranges` when called multiple times.
--

commit 9619ae1d9d691918f8e1f649f853a92424ed440c
Author: Thomas Falcon <thomas.falcon@intel.com>

perf header: Support memory ranges

This commit introduces support for tracking and exposing memory ranges parsed
from the ACPI MRRM table. It reads memory range data from sysfs and saves it
in the perf data file under the new HEADER_MEMORY_RANGES feature bit.

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;
[ ... ]
> +	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;

[Severity: Medium]
Could this result in a memory leak of the previous env->memory_ranges
allocation?

In pipe mode, the perf_event__process_feature() function parses feature
headers as they arrive and dispatches them to process_memory_ranges(). If
the HEADER_MEMORY_RANGES feature is encountered multiple times in a data
stream, this assigns the newly allocated array to env->memory_ranges without
freeing the previous array.

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

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

  reply	other threads:[~2026-09-09 16:15 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09 16:02 [PATCH v7 0/6] perf: Add support for memory region/range reporting Thomas Falcon
2026-09-09 16:02 ` [PATCH v7 1/6] perf mem: Fix size tracking for mem_lvl's in perf_script__meminfo_scnprintf() Thomas Falcon
2026-09-09 16:12   ` sashiko-bot
2026-09-09 16:02 ` [PATCH v7 2/6] perf mem: Add support for printing PERF_MEM_LVLNUM_L0 Thomas Falcon
2026-09-09 16:10   ` sashiko-bot
2026-09-09 16:02 ` [PATCH v7 3/6] perf header: Support memory ranges Thomas Falcon
2026-09-09 16:15   ` sashiko-bot [this message]
2026-09-09 16:02 ` [PATCH v7 4/6] perf tools: Show memory region in perf-c2c subcommand Thomas Falcon
2026-09-09 16:13   ` sashiko-bot
2026-09-10  2:19   ` Mi, Dapeng
2026-09-09 16:02 ` [PATCH v7 5/6] perf tools: Show memory region in perf-script subcommand Thomas Falcon
2026-09-09 16:17   ` sashiko-bot
2026-09-10  2:22   ` Mi, Dapeng
2026-09-10 14:10     ` Arnaldo Carvalho de Melo
2026-09-09 16:02 ` [PATCH v7 6/6] perf c2c: print memory region data with stdio output Thomas Falcon
2026-09-09 16:12   ` 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=20260909161536.294031F00893@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