Skip to contentSkip to conversation

perf map: Fix error return code in maps__clone()

PATCH Applied Zhen Lei 3 participants 4 messages Apr 15, 2021 perf events

lore
Share & tools
lore

Zhen Lei

author
#0 lore raw

PATCH 1/1 perf map: Fix error return code in maps__clone()

Although 'err' has been initialized to -ENOMEM, but it will be reassigned by the "err = unwind__prepare_access(...)" statement in the for loop. So that, the value of 'err' is unknown when map__clone() failed.

---
 tools/perf/util/map.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tools/perf/util/map.c +5 -2
index fbc40a2c17d4dca..8af693d9678cefe 100644
@@ -840,15 +840,18 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
 int maps__clone(struct thread *thread, struct maps *parent)
 {
 	struct maps *maps = thread->maps;
-	int err = -ENOMEM;
+	int err;
 	struct map *map;
 
 	down_read(&parent->lock);
 
 	maps__for_each_entry(parent, map) {
 		struct map *new = map__clone(map);
-		if (new == NULL)
+
+		if (new == NULL) {
+			err = -ENOMEM;
 			goto out_unlock;
+		}
 
 		err = unwind__prepare_access(maps, new, NULL);
 		if (err)
Signature · 1 line
2.26.0.106.g9fadedd
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Zhen Lei

Although 'err' has been initialized to -ENOMEM, but it will be reassigned by the "err = unwind__prepare_access(...)" statement in the for loop. So that, the value of 'err' is unknown when map__clone() failed.

thanks,
jirka

Quoted 33 lines
---
 tools/perf/util/map.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tools/perf/util/map.c +5 -2
index fbc40a2c17d4dca..8af693d9678cefe 100644
@@ -840,15 +840,18 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
 int maps__clone(struct thread *thread, struct maps *parent)
 {
 	struct maps *maps = thread->maps;
-	int err = -ENOMEM;
+	int err;
 	struct map *map;
 
 	down_read(&parent->lock);
 
 	maps__for_each_entry(parent, map) {
 		struct map *new = map__clone(map);
-		if (new == NULL)
+
+		if (new == NULL) {
+			err = -ENOMEM;
 			goto out_unlock;
+		}
 
 		err = unwind__prepare_access(maps, new, NULL);
 		if (err)
Signature · 1 line
2.26.0.106.g9fadedd
maintainer Applied
#2 lore raw
In reply to Zhen Lei

Em Thu, Apr 15, 2021 at 05:27:44PM +0800, Zhen Lei escreveu:

Quoted 3 lines

Although 'err' has been initialized to -ENOMEM, but it will be reassigned by the "err = unwind__prepare_access(...)" statement in the for loop. So that, the value of 'err' is unknown when map__clone() failed.

You forgot to research and add this:

Fixes 6c502584438bda63 ("perf unwind: Call unwind__prepare_access for forked thread")

So that the [email protected] guys can pick this up automagically and apply this fix to the stable kernels.

I've added it.

Thanks, applied.

- Arnaldo

Quoted 35 lines
---
 tools/perf/util/map.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tools/perf/util/map.c +5 -2
index fbc40a2c17d4dca..8af693d9678cefe 100644
@@ -840,15 +840,18 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
 int maps__clone(struct thread *thread, struct maps *parent)
 {
 	struct maps *maps = thread->maps;
-	int err = -ENOMEM;
+	int err;
 	struct map *map;
 
 	down_read(&parent->lock);
 
 	maps__for_each_entry(parent, map) {
 		struct map *new = map__clone(map);
-		if (new == NULL)
+
+		if (new == NULL) {
+			err = -ENOMEM;
 			goto out_unlock;
+		}
 
 		err = unwind__prepare_access(maps, new, NULL);
 		if (err)
Signature · 1 line
2.26.0.106.g9fadedd
Signature · 1 line
- Arnaldo
#3 lore raw
Quoted 5 lines · Arnaldo Carvalho de Melo

Em Thu, Apr 15, 2021 at 05:27:44PM +0800, Zhen Lei escreveu:

Quoted 3 lines

Although 'err' has been initialized to -ENOMEM, but it will be reassigned by the "err = unwind__prepare_access(...)" statement in the for loop. So that, the value of 'err' is unknown when map__clone() failed.

Quoted 8 lines

You forgot to research and add this:

Fixes 6c502584438bda63 ("perf unwind: Call unwind__prepare_access for forked thread")

So that the [email protected] guys can pick this up automagically and apply this fix to the stable kernels.

I've added it.

OK, thank you very much.

Quoted 41 lines

Thanks, applied.

- Arnaldo

Quoted 35 lines
---
 tools/perf/util/map.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tools/perf/util/map.c +5 -2
index fbc40a2c17d4dca..8af693d9678cefe 100644
@@ -840,15 +840,18 @@ int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
 int maps__clone(struct thread *thread, struct maps *parent)
 {
 	struct maps *maps = thread->maps;
-	int err = -ENOMEM;
+	int err;
 	struct map *map;
 
 	down_read(&parent->lock);
 
 	maps__for_each_entry(parent, map) {
 		struct map *new = map__clone(map);
-		if (new == NULL)
+
+		if (new == NULL) {
+			err = -ENOMEM;
 			goto out_unlock;
+		}
 
 		err = unwind__prepare_access(maps, new, NULL);
 		if (err)
Signature · 1 line
2.26.0.106.g9fadedd