Re: [PATCH 1/2] perf c2c: Fix error masking, OOM, and unchecked caller errors in hpp_list__parse()

[email protected] Mon, 03 Aug 2026 18:26:01 +0000
Newsgroups org.kernel.vger.linux-perf-users
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(=
s) to consider:

Pre-existing issues:
- [Medium] The string parsing loops in `setup_sort_list()` and `setup_outpu=
t_list()` silently ignore and overwrite memory allocation errors (-ENOMEM),=
 leading to partially initialized sort or output fields being treated as su=
ccessful.
--

--- Patch [1]: [PATCH 1/2] perf c2c: Fix error masking, OOM, and unchecked =
caller errors in hpp_list__parse() ---
commit eb21379d23b3ae985cd662b484d5da281ac1387b
Author: Arnaldo Carvalho de Melo <[email protected]>

perf c2c: Fix error masking, OOM, and unchecked caller errors in hpp_list__=
parse()

This commit fixes multiple issues in hpp_list__parse(), including error
masking during string parsing, unhandled strdup() OOM failures, and uncheck=
ed
function returns. It also updates underlying sort and output functions to
return -ENOMEM instead of -1 on allocation failures.

> diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
> index 005e7d85dc4a5..616a583e3d4d6 100644
> --- a/tools/perf/util/sort.c
> +++ b/tools/perf/util/sort.c
[ ... ]
> @@ -3882,8 +3889,7 @@ int sort_dimension__add(struct perf_hpp_list *list,=
 const char *tok,
>  		if (sort__mode !=3D SORT_MODE__MEMORY)
>  			return -EINVAL;
> =20
> -		__sort_dimension__add(sd, list, level);
> -		return 0;
> +		return __sort_dimension__add(sd, list, level);
>  	}
> =20
>  	for (i =3D 0; i < ARRAY_SIZE(hpp_sort_dimensions); i++) {

[Severity: Medium]
This is a pre-existing issue, but by explicitly propagating -ENOMEM out of
sort_dimension__add() and output_field_add(), does this highlight a bug in
their callers?

In setup_sort_list() and setup_output_list(), the parsing loops only check
for -EINVAL and -ESRCH:

ret =3D sort_dimension__add(list, tok, evlist, env, level);
if (ret =3D=3D -EINVAL) {
	...
	break;
} else if (ret =3D=3D -ESRCH) {
	...
	break;
}

If sort_dimension__add() or output_field_add() returns -ENOMEM, the loop
continues without breaking, and a subsequent successful token will overwrite
the error. This can cause the perf tool to silently continue with a partial=
ly
configured state instead of aborting on memory allocation failure.

Should these loops be updated to catch other error codes like -ENOMEM?

--=20
Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20260803180703.1949=
[email protected]?part=3D1