perf maps: Get map before returning in maps__find
[linux-2.6-microblaze.git] / tools / perf / util / machine.c
index b397a76..e8eb9f0 100644 (file)
@@ -896,7 +896,6 @@ static int machine__process_ksymbol_register(struct machine *machine,
        struct symbol *sym;
        struct dso *dso;
        struct map *map = maps__find(machine__kernel_maps(machine), event->ksymbol.addr);
-       bool put_map = false;
        int err = 0;
 
        if (!map) {
@@ -913,12 +912,6 @@ static int machine__process_ksymbol_register(struct machine *machine,
                        err = -ENOMEM;
                        goto out;
                }
-               /*
-                * The inserted map has a get on it, we need to put to release
-                * the reference count here, but do it after all accesses are
-                * done.
-                */
-               put_map = true;
                if (event->ksymbol.ksym_type == PERF_RECORD_KSYMBOL_TYPE_OOL) {
                        dso->binary_type = DSO_BINARY_TYPE__OOL;
                        dso->data.file_size = event->ksymbol.len;
@@ -952,8 +945,7 @@ static int machine__process_ksymbol_register(struct machine *machine,
        }
        dso__insert_symbol(dso, sym);
 out:
-       if (put_map)
-               map__put(map);
+       map__put(map);
        return err;
 }
 
@@ -977,7 +969,7 @@ static int machine__process_ksymbol_unregister(struct machine *machine,
                if (sym)
                        dso__delete_symbol(dso, sym);
        }
-
+       map__put(map);
        return 0;
 }
 
@@ -1005,11 +997,11 @@ int machine__process_text_poke(struct machine *machine, union perf_event *event,
                perf_event__fprintf_text_poke(event, machine, stdout);
 
        if (!event->text_poke.new_len)
-               return 0;
+               goto out;
 
        if (cpumode != PERF_RECORD_MISC_KERNEL) {
                pr_debug("%s: unsupported cpumode - ignoring\n", __func__);
-               return 0;
+               goto out;
        }
 
        if (dso) {
@@ -1032,7 +1024,8 @@ int machine__process_text_poke(struct machine *machine, union perf_event *event,
                pr_debug("Failed to find kernel text poke address map for %#" PRI_lx64 "\n",
                         event->text_poke.addr);
        }
-
+out:
+       map__put(map);
        return 0;
 }
 
@@ -1300,9 +1293,10 @@ static int machine__map_x86_64_entry_trampolines_cb(struct map *map, void *data)
                return 0;
 
        dest_map = maps__find(args->kmaps, map__pgoff(map));
-       if (dest_map != map)
+       if (RC_CHK_ACCESS(dest_map) != RC_CHK_ACCESS(map))
                map__set_pgoff(map, map__map_ip(dest_map, map__pgoff(map)));
 
+       map__put(dest_map);
        args->found = true;
        return 0;
 }