Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jiebin Sun" <jiebin.sun@intel.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2 08/14] perf c2c: add HPP list parsing for function view histograms
Date: Fri, 10 Jul 2026 09:01:57 +0000	[thread overview]
Message-ID: <20260710090157.DC6E71F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260710084247.3576706-9-jiebin.sun@intel.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] Calling `reset_dimensions()` for every fallback token in `c2c_function_hists__init_output` and `c2c_function_hists__init_sort` clears the global `taken` flags during string parsing, defeating duplicate field protection.
- [Medium] `function_hpp_list__parse` leaks dynamically allocated `c2c_fmt` elements if token parsing fails midway.
- [Low] Missing newline character in error log in `function_hpp_list__add_tokens`.
--

--- Patch [8]: [PATCH v2 08/14] perf c2c: add HPP list parsing for function view histograms ---
commit 7b3a4ebd5658b8b4b899fd6fb0008adeb8109767
Author: Jiebin Sun <jiebin.sun@intel.com>

perf c2c: add HPP list parsing for function view histograms

This commit adds the histogram initialization and column parsing
infrastructure to bridge the function view's custom dimensions with the perf
HPP list infrastructure. This enables dynamic column configuration during
hierarchy construction.

> diff --git a/tools/perf/ui/browsers/c2c-function.c b/tools/perf/ui/browsers/c2c-function.c
> index 7c2bb8f9e1139..0f21cf39f0ce6 100644
> --- a/tools/perf/ui/browsers/c2c-function.c
> +++ b/tools/perf/ui/browsers/c2c-function.c

[ ... ]

> @@ -502,7 +513,156 @@ static __maybe_unused struct c2c_fmt *get_function_format(const char *name)

[ ... ]

> +static int
> +c2c_function_hists__init_output(struct perf_hpp_list *hpp_list, char *name,
> +				struct perf_env *env __maybe_unused)
> +{
> +	struct c2c_fmt *c2c_fmt;
> +	int level = 0;
> +	int ret;
> +
> +	ret = get_function_format(name, &c2c_fmt);
> +	if (ret == -ENOMEM)
> +		return ret;
> +	if (ret == -ENOENT) {
> +		reset_dimensions();

[Severity: Medium]
Does calling reset_dimensions() here wipe out the global taken flag for all
previously processed tokens? If a user provides a string with multiple
fallback tokens, it seems this clears the flags and defeats the duplicate
field protection, which might allow duplicate columns and lead to
double-frees or list corruption during teardown.

> +		return output_field_add(hpp_list, name, &level);
> +	}

[ ... ]

> +static int
> +c2c_function_hists__init_sort(struct perf_hpp_list *hpp_list, char *name,
> +			      struct perf_env *env)
> +{
> +	struct c2c_fmt *c2c_fmt;
> +	int ret;
> +
> +	ret = get_function_format(name, &c2c_fmt);
> +	if (ret == -ENOMEM)
> +		return ret;
> +	if (ret == -ENOENT) {
> +		reset_dimensions();

[Severity: Medium]
Does this repeated call to reset_dimensions() for sort tokens also cause the
same state corruption as in the output field initialization?

> +		return sort_dimension__add(hpp_list, name, /*evlist=*/NULL, env, /*level=*/0);
> +	}

[ ... ]

> +static int function_hpp_list__add_tokens(struct perf_hpp_list *hpp_list, char *list,
> +					 struct perf_env *env, hpp_list_add_fn add)
> +{
> +	char *tok, *tmp;
> +	int ret;
> +
> +	if (!list)
> +		return 0;
> +
> +	for (tok = strtok_r(list, ", ", &tmp); tok; tok = strtok_r(NULL, ", ", &tmp)) {
> +		ret = add(hpp_list, tok, env);
> +		if (ret) {
> +			if (ret == -EINVAL || ret == -ESRCH)
> +				pr_err("Invalid c2c function-view field: %s", tok);

[Severity: Low]
This isn't a bug, but does this pr_err() need a trailing '\n' to prevent
garbled terminal output? The pr_err() macro in tools/perf wraps eprintf
and does not implicitly append a newline.

> +			return ret;
> +		}
> +	}
> +	return 0;
> +}
> +
> +static int
> +function_hpp_list__parse(struct perf_hpp_list *hpp_list,
> +			 const char *output_str,
> +			 const char *sort_str,
> +			 struct perf_env *env)
> +{
> +	char *output = output_str ? strdup(output_str) : NULL;
> +	char *sort   = sort_str   ? strdup(sort_str)   : NULL;
> +	int ret = 0;
> +
> +	if ((output_str && !output) || (sort_str && !sort)) {
> +		ret = -ENOMEM;
> +		goto out;
> +	}
> +
> +	ret = function_hpp_list__add_tokens(hpp_list, output, env,
> +					    c2c_function_hists__init_output);
> +	if (ret)
> +		goto out;

[Severity: Medium]
If function_hpp_list__add_tokens() fails midway and returns an error, does
this goto out leak the dynamically allocated c2c_fmt elements? It appears
the previously allocated and registered elements in hpp_list are not freed
when bypassing the normal cleanup path.

> +
> +	ret = function_hpp_list__add_tokens(hpp_list, sort, env,
> +					    c2c_function_hists__init_sort);
> +	if (ret)
> +		goto out;

[Severity: Medium]
Does returning early here if the sort string parsing fails also leak the
allocations already made during the output string parsing?

> +
> +	perf_hpp__setup_output_field(hpp_list);
> +out:
> +	free(output);
> +	free(sort);
> +	return ret;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260710084247.3576706-1-jiebin.sun@intel.com?part=8

  reply	other threads:[~2026-07-10  9:01 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-26  7:03 [PATCH 00/14] perf c2c: add a function view Jiebin Sun
2026-06-26  7:03 ` [PATCH 01/14] perf c2c: extract shared data structures into c2c.h Jiebin Sun
2026-06-26  7:13   ` sashiko-bot
2026-06-26  7:03 ` [PATCH 02/14] perf c2c: add function view browser skeleton Jiebin Sun
2026-06-26  7:11   ` sashiko-bot
2026-06-26  7:03 ` [PATCH 03/14] perf c2c: add function view type definitions and helpers Jiebin Sun
2026-06-26  7:14   ` sashiko-bot
2026-06-26  7:03 ` [PATCH 04/14] perf c2c: add column format infrastructure for function view Jiebin Sun
2026-06-26  7:03 ` [PATCH 05/14] perf c2c: add column entry functions " Jiebin Sun
2026-06-26  7:03 ` [PATCH 06/14] perf c2c: add comparison functions for function view sorting Jiebin Sun
2026-06-26  7:22   ` sashiko-bot
2026-06-26  7:03 ` [PATCH 07/14] perf c2c: add dimension definitions and format creation Jiebin Sun
2026-06-26  7:23   ` sashiko-bot
2026-06-26  7:03 ` [PATCH 08/14] perf c2c: add HPP list parsing for function view histograms Jiebin Sun
2026-06-26  7:16   ` sashiko-bot
2026-06-26  7:03 ` [PATCH 09/14] perf c2c: add stats merging and memory management helpers Jiebin Sun
2026-06-26  7:17   ` sashiko-bot
2026-06-26  7:03 ` [PATCH 10/14] perf c2c: add hierarchy entry creation and lookup functions Jiebin Sun
2026-06-26  7:19   ` sashiko-bot
2026-06-26  7:03 ` [PATCH 11/14] perf c2c: add function view hierarchy builder Jiebin Sun
2026-06-26  7:03 ` [PATCH 12/14] perf c2c: add function view browser UI Jiebin Sun
2026-06-26  7:03 ` [PATCH 13/14] perf c2c: add TAB key to switch to function view Jiebin Sun
2026-06-26  7:03 ` [PATCH 14/14] perf c2c: document function view in perf-c2c man page Jiebin Sun
2026-07-07  0:41 ` [PATCH 00/14] perf c2c: add a function view Namhyung Kim
2026-07-10  8:49   ` Jiebin Sun
2026-07-10 21:54     ` Namhyung Kim
2026-07-10  8:42 ` [PATCH v2 " Jiebin Sun
2026-07-10  8:42   ` [PATCH v2 01/14] perf c2c: extract shared data structures into c2c.h Jiebin Sun
2026-07-10  8:54     ` sashiko-bot
2026-07-10  8:42   ` [PATCH v2 02/14] perf c2c: add function view browser skeleton Jiebin Sun
2026-07-10  8:50     ` sashiko-bot
2026-07-10  8:42   ` [PATCH v2 03/14] perf c2c: add function view type definitions and helpers Jiebin Sun
2026-07-10  8:42   ` [PATCH v2 04/14] perf c2c: add column format infrastructure for function view Jiebin Sun
2026-07-10  9:00     ` sashiko-bot
2026-07-10  8:42   ` [PATCH v2 05/14] perf c2c: add column entry functions " Jiebin Sun
2026-07-10  8:42   ` [PATCH v2 06/14] perf c2c: add comparison functions for function view sorting Jiebin Sun
2026-07-10  8:42   ` [PATCH v2 07/14] perf c2c: add dimension definitions and format creation Jiebin Sun
2026-07-10  8:42   ` [PATCH v2 08/14] perf c2c: add HPP list parsing for function view histograms Jiebin Sun
2026-07-10  9:01     ` sashiko-bot [this message]
2026-07-10  8:42   ` [PATCH v2 09/14] perf c2c: add stats merging and memory management helpers Jiebin Sun
2026-07-10  8:42   ` [PATCH v2 10/14] perf c2c: add hierarchy entry creation and lookup functions Jiebin Sun
2026-07-10  8:42   ` [PATCH v2 11/14] perf c2c: add function view hierarchy builder Jiebin Sun
2026-07-10  9:01     ` sashiko-bot
2026-07-10  8:42   ` [PATCH v2 12/14] perf c2c: add function view browser UI Jiebin Sun
2026-07-10  8:42   ` [PATCH v2 13/14] perf c2c: add TAB key to switch to function view Jiebin Sun
2026-07-10  8:42   ` [PATCH v2 14/14] perf c2c: document function view in perf-c2c man page Jiebin Sun

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=20260710090157.DC6E71F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=jiebin.sun@intel.com \
    --cc=linux-perf-users@vger.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