[PATCH v2 02/11] perf evlist: Add success path to evlist__create_syswide_maps

Ian Rogers posted 11 patches 9 months, 3 weeks ago
[PATCH v2 02/11] perf evlist: Add success path to evlist__create_syswide_maps
Posted by Ian Rogers 9 months, 3 weeks ago
Over various refactorings evlist__create_syswide_maps has been made to
only ever return with -ENOMEM. Fix this so that when
perf_evlist__set_maps is successfully called, 0 is returned.

Reviewed-by: Howard Chu <howardchu95@gmail.com>
Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/evlist.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index f0dd174e2deb..633df7d9204c 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1373,19 +1373,18 @@ static int evlist__create_syswide_maps(struct evlist *evlist)
 	 */
 	cpus = perf_cpu_map__new_online_cpus();
 	if (!cpus)
-		goto out;
+		return -ENOMEM;
 
 	threads = perf_thread_map__new_dummy();
-	if (!threads)
-		goto out_put;
+	if (!threads) {
+		perf_cpu_map__put(cpus);
+		return -ENOMEM;
+	}
 
 	perf_evlist__set_maps(&evlist->core, cpus, threads);
-
 	perf_thread_map__put(threads);
-out_put:
 	perf_cpu_map__put(cpus);
-out:
-	return -ENOMEM;
+	return 0;
 }
 
 int evlist__open(struct evlist *evlist)
-- 
2.48.1.711.g2feabab25a-goog
Re: [PATCH v2 02/11] perf evlist: Add success path to evlist__create_syswide_maps
Posted by Arnaldo Carvalho de Melo 9 months, 2 weeks ago
On Fri, Feb 28, 2025 at 02:22:59PM -0800, Ian Rogers wrote:
> Over various refactorings evlist__create_syswide_maps has been made to
> only ever return with -ENOMEM. Fix this so that when
> perf_evlist__set_maps is successfully called, 0 is returned.

I think this was when the problem was introduced:

Fixes: 8c0498b6891d7ca5 ("perf evlist: Fix create_syswide_maps() not propagating maps")

Reviewed-by: Arnaldo Carvalho de Melo <acme@redhat.com>

- Arnaldo
 
> Reviewed-by: Howard Chu <howardchu95@gmail.com>
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/util/evlist.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
> index f0dd174e2deb..633df7d9204c 100644
> --- a/tools/perf/util/evlist.c
> +++ b/tools/perf/util/evlist.c
> @@ -1373,19 +1373,18 @@ static int evlist__create_syswide_maps(struct evlist *evlist)
>  	 */
>  	cpus = perf_cpu_map__new_online_cpus();
>  	if (!cpus)
> -		goto out;
> +		return -ENOMEM;
>  
>  	threads = perf_thread_map__new_dummy();
> -	if (!threads)
> -		goto out_put;
> +	if (!threads) {
> +		perf_cpu_map__put(cpus);
> +		return -ENOMEM;
> +	}
>  
>  	perf_evlist__set_maps(&evlist->core, cpus, threads);
> -
>  	perf_thread_map__put(threads);
> -out_put:
>  	perf_cpu_map__put(cpus);
> -out:
> -	return -ENOMEM;
> +	return 0;
>  }
>  
>  int evlist__open(struct evlist *evlist)
> -- 
> 2.48.1.711.g2feabab25a-goog