[PATCH v2 06/26] perf addr_location: Add init/exit/copy functions

Arnaldo Carvalho de Melo acme at kernel.org
Fri Jun 9 12:48:04 PDT 2023


Em Thu, Jun 08, 2023 at 04:28:03PM -0700, Ian Rogers escreveu:
> +++ b/tools/perf/builtin-kmem.c
> @@ -399,7 +399,9 @@ static u64 find_callsite(struct evsel *evsel, struct perf_sample *sample)
>  	struct addr_location al;
>  	struct machine *machine = &kmem_session->machines.host;
>  	struct callchain_cursor_node *node;
> +	u64 result;
>  
> +	addr_location__init(&al);
>  	if (alloc_func_list == NULL) {
>  		if (build_alloc_func_list() < 0)
>  			goto out;
> @@ -427,16 +429,19 @@ static u64 find_callsite(struct evsel *evsel, struct perf_sample *sample)
>  			else
>  				addr = node->ip;
>  
> -			return addr;
> +			result = addr;
> +			goto out;
>  		} else
>  			pr_debug3("skipping alloc function: %s\n", caller->name);
>  
>  		callchain_cursor_advance(&callchain_cursor);
>  	}
>  
> -out:
>  	pr_debug2("unknown callsite: %"PRIx64 "\n", sample->ip);
> -	return sample->ip;
> +	result = sample->ip;
> +out:
> +	addr_location__exit(&al);
> +	return result;
>  }

I needed this to make sure result is set to something, mostly keeping
the previous logic as build_alloc_func_list() already does
debugging/error prints about what went wrong if it takes the 'goto out'.

- Arnaldo

diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index a11f280d20bd3d12..96a6611e4e53f448 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -399,7 +399,7 @@ static u64 find_callsite(struct evsel *evsel, struct perf_sample *sample)
 	struct addr_location al;
 	struct machine *machine = &kmem_session->machines.host;
 	struct callchain_cursor_node *node;
-	u64 result;
+	u64 result = sample->ip;
 
 	addr_location__init(&al);
 	if (alloc_func_list == NULL) {
@@ -438,7 +438,6 @@ static u64 find_callsite(struct evsel *evsel, struct perf_sample *sample)
 	}
 
 	pr_debug2("unknown callsite: %"PRIx64 "\n", sample->ip);
-	result = sample->ip;
 out:
 	addr_location__exit(&al);
 	return result;



More information about the linux-arm-kernel mailing list