Skip to contentSkip to conversation

perf map: Fix map reference count issues

PATCH Applied Ian Rogers 2 participants 3 messages Feb 29, 2024 – Mar 1, 2024 perf events

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 perf map: Fix map reference count issues

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

---
 tools/perf/util/maps.c        | 14 +++++++-------
 tools/perf/util/probe-event.c |  4 +---
 2 files changed, 8 insertions(+), 10 deletions(-)
tools/perf/util/maps.c +7 -7
index 53aea6d2ef93..ce13145a9f8e 100644
@@ -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;
 }
 
tools/perf/util/probe-event.c +1 -3
index be71abe8b9b0..2a0ad9ecf0a2 100644
@@ -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;
 }
Signature · 1 line
2.44.0.278.ge034bb2e1d-goog
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Ian Rogers

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

Thanks,
Namhyung

Quoted 49 lines
---
 tools/perf/util/maps.c        | 14 +++++++-------
 tools/perf/util/probe-event.c |  4 +---
 2 files changed, 8 insertions(+), 10 deletions(-)
tools/perf/util/maps.c +7 -7
index 53aea6d2ef93..ce13145a9f8e 100644
@@ -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;
 }
 
tools/perf/util/probe-event.c +1 -4
index be71abe8b9b0..2a0ad9ecf0a2 100644
@@ -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