linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] perf map: Fix map reference count issues
@ 2024-02-29  6:20 Ian Rogers
  2024-03-01  2:04 ` Namhyung Kim
  2024-03-01 19:31 ` Namhyung Kim
  0 siblings, 2 replies; 3+ messages in thread
From: Ian Rogers @ 2024-02-29  6:20 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, Masami Hiramatsu, linux-perf-users,
	linux-kernel

The find will get the map, ensure puts are done on all paths.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/maps.c        | 14 +++++++-------
 tools/perf/util/probe-event.c |  4 +---
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c
index 53aea6d2ef93..ce13145a9f8e 100644
--- a/tools/perf/util/maps.c
+++ b/tools/perf/util/maps.c
@@ -611,14 +611,14 @@ struct symbol *maps__find_symbol(struct maps *maps, u64 addr, struct map **mapp)
 	struct symbol *result = NULL;
 
 	/* Ensure map is loaded before using map->map_ip */
-	if (map != NULL && map__load(map) >= 0) {
-		if (mapp)
-			*mapp = map;
-
+	if (map != NULL && map__load(map) >= 0)
 		result = map__find_symbol(map, map__map_ip(map, addr));
-		if (!mapp)
-			map__put(map);
-	}
+
+	if (mapp)
+		*mapp = map;
+	else
+		map__put(map);
+
 	return result;
 }
 
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index be71abe8b9b0..2a0ad9ecf0a2 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -2274,9 +2274,7 @@ static int find_perf_probe_point_from_map(struct probe_trace_point *tp,
 	ret = pp->function ? 0 : -ENOMEM;
 
 out:
-	if (map && !is_kprobe) {
-		map__put(map);
-	}
+	map__put(map);
 
 	return ret;
 }
-- 
2.44.0.278.ge034bb2e1d-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] perf map: Fix map reference count issues
  2024-02-29  6:20 [PATCH v1] perf map: Fix map reference count issues Ian Rogers
@ 2024-03-01  2:04 ` Namhyung Kim
  2024-03-01 19:31 ` Namhyung Kim
  1 sibling, 0 replies; 3+ messages in thread
From: Namhyung Kim @ 2024-03-01  2:04 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
	Masami Hiramatsu, linux-perf-users, linux-kernel

On Wed, Feb 28, 2024 at 10:21 PM Ian Rogers <irogers@google.com> wrote:
>
> The find will get the map, ensure puts are done on all paths.
>
> Signed-off-by: Ian Rogers <irogers@google.com>

Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks,
Namhyung


> ---
>  tools/perf/util/maps.c        | 14 +++++++-------
>  tools/perf/util/probe-event.c |  4 +---
>  2 files changed, 8 insertions(+), 10 deletions(-)
>
> diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c
> index 53aea6d2ef93..ce13145a9f8e 100644
> --- a/tools/perf/util/maps.c
> +++ b/tools/perf/util/maps.c
> @@ -611,14 +611,14 @@ struct symbol *maps__find_symbol(struct maps *maps, u64 addr, struct map **mapp)
>         struct symbol *result = NULL;
>
>         /* Ensure map is loaded before using map->map_ip */
> -       if (map != NULL && map__load(map) >= 0) {
> -               if (mapp)
> -                       *mapp = map;
> -
> +       if (map != NULL && map__load(map) >= 0)
>                 result = map__find_symbol(map, map__map_ip(map, addr));
> -               if (!mapp)
> -                       map__put(map);
> -       }
> +
> +       if (mapp)
> +               *mapp = map;
> +       else
> +               map__put(map);
> +
>         return result;
>  }
>
> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
> index be71abe8b9b0..2a0ad9ecf0a2 100644
> --- a/tools/perf/util/probe-event.c
> +++ b/tools/perf/util/probe-event.c
> @@ -2274,9 +2274,7 @@ static int find_perf_probe_point_from_map(struct probe_trace_point *tp,
>         ret = pp->function ? 0 : -ENOMEM;
>
>  out:
> -       if (map && !is_kprobe) {
> -               map__put(map);
> -       }
> +       map__put(map);
>
>         return ret;
>  }
> --
> 2.44.0.278.ge034bb2e1d-goog
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] perf map: Fix map reference count issues
  2024-02-29  6:20 [PATCH v1] perf map: Fix map reference count issues Ian Rogers
  2024-03-01  2:04 ` Namhyung Kim
@ 2024-03-01 19:31 ` Namhyung Kim
  1 sibling, 0 replies; 3+ messages in thread
From: Namhyung Kim @ 2024-03-01 19:31 UTC (permalink / raw)
  To: Ian Rogers, Peter Zijlstra, Alexander Shishkin, Masami Hiramatsu,
	Mark Rutland, linux-kernel, Jiri Olsa, Arnaldo Carvalho de Melo,
	Adrian Hunter, linux-perf-users, Ingo Molnar

On Wed, 28 Feb 2024 22:20:48 -0800, Ian Rogers wrote:
> The find will get the map, ensure puts are done on all paths.
> 
> 

Applied to perf-tools-next, thanks!

Best regards,
-- 
Namhyung Kim <namhyung@kernel.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-03-01 19:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-29  6:20 [PATCH v1] perf map: Fix map reference count issues Ian Rogers
2024-03-01  2:04 ` Namhyung Kim
2024-03-01 19:31 ` Namhyung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).