perf map: Allow map__next() to receive a NULL arg
authorArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 28 Oct 2019 14:50:12 +0000 (11:50 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 6 Nov 2019 18:43:06 +0000 (15:43 -0300)
Just like free(), return NULL in that case, will simplify the
for_each_entry_safe() iterators.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-pbde2ucn49khnrebclys9pny@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/map.c

index c9ba495..86d8d18 100644 (file)
@@ -1007,7 +1007,7 @@ struct map *maps__first(struct maps *maps)
        return NULL;
 }
 
-struct map *map__next(struct map *map)
+static struct map *__map__next(struct map *map)
 {
        struct rb_node *next = rb_next(&map->rb_node);
 
@@ -1016,6 +1016,11 @@ struct map *map__next(struct map *map)
        return NULL;
 }
 
+struct map *map__next(struct map *map)
+{
+       return map ? __map__next(map) : NULL;
+}
+
 struct kmap *__map__kmap(struct map *map)
 {
        if (!map->dso || !map->dso->kernel)