[RFT PATCH 1/7] perf stat: Check color's length instead of the pointer
Jonathan Cameron
jonathan.cameron at huawei.com
Tue Jan 27 07:58:35 PST 2026
On Mon, 26 Jan 2026 20:35:08 +0800
Yushan Wang <wangyushan12 at huawei.com> wrote:
> Color string returned by metric_threshold_classify__color() is never
> NULL, check the presence of *color will always return true.
>
> Fix this by change the checks against length of *color.
>
> Fixes: 37b77ae95416 ("perf stat: Change color to threshold in print_metric")
>
No blank line between tags.
Fixes: 37b77ae95416 ("perf stat: Change color to threshold in print_metric")
Signed-off-by: Yushan Wang <wangyushan12 at huawei.com>
Some of the scripting run against the kernel uses that lack of blank lines
as a heuristic to identify what is a tag vs other similar looking text.
Thanks,
Jonathan
> Signed-off-by: Yushan Wang <wangyushan12 at huawei.com>
> ---
> tools/perf/builtin-script.c | 2 +-
> tools/perf/util/stat-display.c | 4 ++--
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index 62e43d3c5ad7..9fe90f564c69 100644
> --- a/tools/perf/builtin-script.c
> +++ b/tools/perf/builtin-script.c
> @@ -2100,7 +2100,7 @@ static void script_print_metric(struct perf_stat_config *config __maybe_unused,
> perf_sample__fprintf_start(NULL, mctx->sample, mctx->thread, mctx->evsel,
> PERF_RECORD_SAMPLE, mctx->fp);
> fputs("\tmetric: ", mctx->fp);
> - if (color)
> + if (strlen(color))
> color_fprintf(mctx->fp, color, fmt, val);
> else
> printf(fmt, val);
> diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
> index 6d02f84c5691..91c0c1020f4e 100644
> --- a/tools/perf/util/stat-display.c
> +++ b/tools/perf/util/stat-display.c
> @@ -474,7 +474,7 @@ static void print_metric_std(struct perf_stat_config *config,
> do_new_line_std(config, os);
>
> n = fprintf(out, " # ");
> - if (color)
> + if (strlen(color))
> n += color_fprintf(out, color, fmt, val);
> else
> n += fprintf(out, fmt, val);
> @@ -607,7 +607,7 @@ static void print_metric_only(struct perf_stat_config *config,
> if (mlen < strlen(unit))
> mlen = strlen(unit) + 1;
>
> - if (color)
> + if (strlen(color))
> mlen += strlen(color) + sizeof(PERF_COLOR_RESET) - 1;
>
> color_snprintf(str, sizeof(str), color ?: "", fmt ?: "", val);
More information about the linux-arm-kernel
mailing list