From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [RFC PATCH v1 01/14] perf stat: Introduce core generic print traversal engine and header stubs
Date: Fri, 22 May 2026 23:47:08 +0000 [thread overview]
Message-ID: <20260522234709.41F381F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260522223342.2393553-2-irogers@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Unconditional invocation of `cb->print_metric` without verifying the callback pointer.
--
commit 90d8e5db3452e883fc9b511756f3c3b819d1ad40
Author: Ian Rogers <irogers@google.com>
perf stat: Introduce core generic print traversal engine and header stubs
This commit introduces the initial infrastructure for decoupling the perf stat
printing API. It declares the struct perf_stat_print_callbacks interface and
implements the core traversal driver perf_stat__print_cb().
> diff --git a/tools/perf/util/stat-print.c b/tools/perf/util/stat-print.c
> index 0000000000000..3a634396c7c63
> --- /dev/null
> +++ b/tools/perf/util/stat-print.c
[ ... ]
> +static int calculate_and_print_metric(const struct perf_stat_config *config,
> + const struct perf_stat_print_callbacks *cb, void *outer_ctx,
> + struct metric_expr *mexp, struct evsel *evsel, int aggr_idx)
> +{
[ ... ]
> + if (!metric_events[i]) {
> + if (expr__parse(&ratio, pctx, metric_expr) == 0) {
> + char *unit;
> +
> + if (metric_threshold &&
> + expr__parse(&threshold, pctx, metric_threshold) == 0 &&
> + !isnan(threshold)) {
> + thresh = fpclassify(threshold) == FP_ZERO ? METRIC_THRESHOLD_GOOD :
> + METRIC_THRESHOLD_BAD;
> + }
> +
> + if (metric_unit && metric_name) {
> + if (perf_pmu__convert_scale(metric_unit, &unit, &scale) >= 0) {
> + ratio *= scale;
> + }
> + ret = cb->print_metric(outer_ctx, config, evsel, aggr_idx,
> + metric_name, unit, ratio, thresh);
> + } else {
> + ret = cb->print_metric(outer_ctx, config, evsel, aggr_idx,
> + metric_name ?: (evsel->name ?: ""), NULL,
> + ratio, thresh);
> + }
[Severity: Medium]
Could this cause a NULL pointer dereference if a caller implements the new API
but omits the print_metric callback?
Looking at perf_stat__print_cb(), callbacks like print_start, print_event,
and print_end are explicitly checked before invocation, which implies that
the callback pointers are treated as optional:
> +int perf_stat__print_cb(struct evlist *evlist, const struct perf_stat_config *config,
[ ... ]
> + if (cb->print_start) {
> + ret = cb->print_start(ctx, config);
> + if (ret)
> + return ret;
> + }
[ ... ]
> + if (cb->print_event) {
> + double stdev_pct = 0.0;
[ ... ]
> + ret = cb->print_event(ctx, config, counter,
> + aggr_idx, val, ena, run,
> + stdev_pct);
Should print_metric be conditionally checked in calculate_and_print_metric() as
well to ensure safety if it is left unpopulated?
> + }
> + }
> +
> + expr__ctx_free(pctx);
> + return ret;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260522223342.2393553-1-irogers@google.com?part=1
next prev parent reply other threads:[~2026-05-22 23:47 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-22 22:33 [RFC PATCH v1 00/14] perf stat: Decouple and modularize metrics/events output printing API Ian Rogers
2026-05-22 22:33 ` [RFC PATCH v1 01/14] perf stat: Introduce core generic print traversal engine and header stubs Ian Rogers
2026-05-22 23:47 ` sashiko-bot [this message]
2026-05-22 22:33 ` [RFC PATCH v1 02/14] perf stat: Implement standard console (STD) formatting callbacks Ian Rogers
2026-05-22 22:54 ` sashiko-bot
2026-05-22 22:33 ` [RFC PATCH v1 03/14] perf stat: Extend STD output linter to test basic New API checks Ian Rogers
2026-05-22 22:33 ` [RFC PATCH v1 04/14] perf stat: Extend STD output linter to test core aggregation checks Ian Rogers
2026-05-22 22:33 ` [RFC PATCH v1 05/14] perf stat: Extend STD output linter to test advanced PMU checks Ian Rogers
2026-05-22 22:33 ` [RFC PATCH v1 06/14] perf stat: Extend STD output linter to test metric-only checks Ian Rogers
2026-05-22 22:33 ` [RFC PATCH v1 07/14] perf stat: Implement CSV formatting callbacks Ian Rogers
2026-05-22 23:01 ` sashiko-bot
2026-05-22 22:33 ` [RFC PATCH v1 08/14] perf stat: Extend CSV output linter to test core aggregation checks Ian Rogers
2026-05-22 22:59 ` sashiko-bot
2026-05-22 22:33 ` [RFC PATCH v1 09/14] perf stat: Extend CSV output linter to test advanced PMU and metric-only checks Ian Rogers
2026-05-22 22:48 ` sashiko-bot
2026-05-22 22:33 ` [RFC PATCH v1 10/14] perf stat: Implement streaming JSON formatting callbacks Ian Rogers
2026-05-22 23:02 ` sashiko-bot
2026-05-22 22:33 ` [RFC PATCH v1 11/14] perf stat: Extend JSON output linter to test core aggregation checks Ian Rogers
2026-05-22 22:53 ` sashiko-bot
2026-05-22 22:33 ` [RFC PATCH v1 12/14] perf stat: Extend JSON output linter to test advanced PMU and metric-only checks Ian Rogers
2026-05-22 22:33 ` [RFC PATCH v1 13/14] perf stat: Add --new support to PMU metrics Python validator Ian Rogers
2026-05-22 22:33 ` [RFC PATCH v1 14/14] perf stat: Extend PMU metrics value linter to validate --new outputs Ian Rogers
2026-05-25 23:18 ` [RFC PATCH v2 00/14] perf stat: Decouple and modularize metrics/events output printing API Ian Rogers
2026-05-25 23:18 ` [RFC PATCH v2 01/14] perf stat: Introduce core generic print traversal engine and header stubs Ian Rogers
2026-05-25 23:38 ` Arnaldo Carvalho de Melo
2026-05-25 23:48 ` Ian Rogers
2026-05-26 0:20 ` Arnaldo Carvalho de Melo
2026-05-25 23:18 ` [RFC PATCH v2 02/14] perf stat: Implement standard console (STD) formatting callbacks Ian Rogers
2026-05-25 23:49 ` Arnaldo Carvalho de Melo
2026-05-26 0:09 ` Ian Rogers
2026-05-25 23:53 ` sashiko-bot
2026-05-25 23:18 ` [RFC PATCH v2 03/14] perf stat: Extend STD output linter to test basic New API checks Ian Rogers
2026-05-25 23:39 ` Arnaldo Carvalho de Melo
2026-05-25 23:18 ` [RFC PATCH v2 04/14] perf stat: Extend STD output linter to test core aggregation checks Ian Rogers
2026-05-25 23:18 ` [RFC PATCH v2 05/14] perf stat: Extend STD output linter to test advanced PMU checks Ian Rogers
2026-05-25 23:18 ` [RFC PATCH v2 06/14] perf stat: Extend STD output linter to test metric-only checks Ian Rogers
2026-05-25 23:18 ` [RFC PATCH v2 07/14] perf stat: Implement CSV formatting callbacks Ian Rogers
2026-05-25 23:18 ` [RFC PATCH v2 08/14] perf stat: Extend CSV output linter to test core aggregation checks Ian Rogers
2026-05-25 23:18 ` [RFC PATCH v2 09/14] perf stat: Extend CSV output linter to test advanced PMU and metric-only checks Ian Rogers
2026-05-25 23:18 ` [RFC PATCH v2 10/14] perf stat: Implement streaming JSON formatting callbacks Ian Rogers
2026-05-25 23:18 ` [RFC PATCH v2 11/14] perf stat: Extend JSON output linter to test core aggregation checks Ian Rogers
2026-05-25 23:18 ` [RFC PATCH v2 12/14] perf stat: Extend JSON output linter to test advanced PMU and metric-only checks Ian Rogers
2026-05-25 23:18 ` [RFC PATCH v2 13/14] perf stat: Add --new support to PMU metrics Python validator Ian Rogers
2026-05-25 23:19 ` [RFC PATCH v2 14/14] perf stat: Extend PMU metrics value linter to validate --new outputs Ian Rogers
2026-05-25 23:53 ` sashiko-bot
2026-06-05 18:02 ` [RFC PATCH v2 00/14] perf stat: Decouple and modularize metrics/events output printing API Chun-Tse Shao
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=20260522234709.41F381F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=irogers@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.