Skip to contentSkip to conversation

perf bench: fix return value check in do_run_multi_threaded()

PATCH Applied YueHaibing 3 participants 7 messages Sep 2, 2020 – Sep 4, 2020 perf events

lore
Share & tools
lore

YueHaibing

author
#0 lore raw

PATCH 1/1 perf bench: fix return value check in do_run_multi_threaded()

In case of error, the function perf_session__new() returns ERR_PTR() and never returns NULL. The NULL test in the return value check should be replaced with IS_ERR()

Fixes 13edc237200c ("perf bench: Add a multi-threaded synthesize benchmark")
---
 tools/perf/bench/synthesize.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/bench/synthesize.c +2 -2
index 8d624aea1c5e..e39daa609db2 100644
@@ -162,8 +162,8 @@ static int do_run_multi_threaded(struct target *target,
 	init_stats(&event_stats);
 	for (i = 0; i < multi_iterations; i++) {
 		session = perf_session__new(NULL, false, NULL);
-		if (!session)
-			return -ENOMEM;
+		if (IS_ERR(session)) {
+			return PTR_ERR(session);
 
 		atomic_set(&event_count, 0);
 		gettimeofday(&start, NULL);
Signature · 1 line
2.17.1
reviewer Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · YueHaibing

In case of error, the function perf_session__new() returns ERR_PTR() and never returns NULL. The NULL test in the return value check should be replaced with IS_ERR()

Fixes 13edc237200c ("perf bench: Add a multi-threaded synthesize benchmark")

Thanks!
Ian

Quoted 23 lines
---
 tools/perf/bench/synthesize.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/bench/synthesize.c +2 -3
index 8d624aea1c5e..e39daa609db2 100644
@@ -162,8 +162,8 @@ static int do_run_multi_threaded(struct target *target,
        init_stats(&event_stats);
        for (i = 0; i < multi_iterations; i++) {
                session = perf_session__new(NULL, false, NULL);
-               if (!session)
-                       return -ENOMEM;
+               if (IS_ERR(session)) {
+                       return PTR_ERR(session);
 
                atomic_set(&event_count, 0);
                gettimeofday(&start, NULL);
--

2.17.1

maintainer Applied
#2 lore raw
In reply to YueHaibing

Em Wed, Sep 02, 2020 at 10:05:26PM +0800, YueHaibing escreveu:

Quoted 6 lines

In case of error, the function perf_session__new() returns ERR_PTR() and never returns NULL. The NULL test in the return value check should be replaced with IS_ERR()

Fixes 13edc237200c ("perf bench: Add a multi-threaded synthesize benchmark")

Thanks, applied, kudos for adding the Fixes: tag, appreciated!

- Arnaldo

Quoted 23 lines
---
 tools/perf/bench/synthesize.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/bench/synthesize.c +2 -2
index 8d624aea1c5e..e39daa609db2 100644
@@ -162,8 +162,8 @@ static int do_run_multi_threaded(struct target *target,
 	init_stats(&event_stats);
 	for (i = 0; i < multi_iterations; i++) {
 		session = perf_session__new(NULL, false, NULL);
-		if (!session)
-			return -ENOMEM;
+		if (IS_ERR(session)) {
+			return PTR_ERR(session);
 
 		atomic_set(&event_count, 0);
 		gettimeofday(&start, NULL);
Signature · 1 line
2.17.1
Signature · 1 line
- Arnaldo
#3 lore raw

Em Thu, Sep 03, 2020 at 03:53:01PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 9 lines

Em Wed, Sep 02, 2020 at 10:05:26PM +0800, YueHaibing escreveu:

Quoted 6 lines

In case of error, the function perf_session__new() returns ERR_PTR() and never returns NULL. The NULL test in the return value check should be replaced with IS_ERR()

Fixes 13edc237200c ("perf bench: Add a multi-threaded synthesize benchmark")

Thanks, applied, kudos for adding the Fixes: tag, appreciated!

But...

Quoted 4 lines
Quoted 4 lines
---
 tools/perf/bench/synthesize.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 12 lines

tools/perf/bench/synthesize.c static int do_run_multi_threaded(struct target *target, · line 166

Quoted 12 lines
tools/perf/bench/synthesize.c +2 -2
index 8d624aea1c5e..e39daa609db2 100644
@@ -162,8 +162,8 @@ static int do_run_multi_threaded(struct target *target,
 	init_stats(&event_stats);
 	for (i = 0; i < multi_iterations; i++) {
 		session = perf_session__new(NULL, false, NULL);
-		if (!session)
-			return -ENOMEM;
+		if (IS_ERR(session)) {
+			return PTR_ERR(session);

This doesn't compile, so I take back that kudo ;-\

I'm fixing this by removing that needless '{'.

Please be more careful,

- Arnaldo

Quoted 11 lines
Quoted 7 lines
tools/perf/bench/synthesize.c +0 -0
 		atomic_set(&event_count, 0);
 		gettimeofday(&start, NULL);
Signature · 1 line
2.17.1
Signature · 1 line
- Arnaldo
Signature · 1 line
- Arnaldo
#4 lore raw

Em Thu, Sep 03, 2020 at 03:54:51PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 32 lines

Em Thu, Sep 03, 2020 at 03:53:01PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 9 lines

Em Wed, Sep 02, 2020 at 10:05:26PM +0800, YueHaibing escreveu:

Quoted 6 lines

In case of error, the function perf_session__new() returns ERR_PTR() and never returns NULL. The NULL test in the return value check should be replaced with IS_ERR()

Fixes 13edc237200c ("perf bench: Add a multi-threaded synthesize benchmark")

Thanks, applied, kudos for adding the Fixes: tag, appreciated!

But...

Quoted 4 lines
Quoted 4 lines
---
 tools/perf/bench/synthesize.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 12 lines

tools/perf/bench/synthesize.c static int do_run_multi_threaded(struct target *target, · line 166

Quoted 12 lines
tools/perf/bench/synthesize.c +2 -2
index 8d624aea1c5e..e39daa609db2 100644
@@ -162,8 +162,8 @@ static int do_run_multi_threaded(struct target *target,
 	init_stats(&event_stats);
 	for (i = 0; i < multi_iterations; i++) {
 		session = perf_session__new(NULL, false, NULL);
-		if (!session)
-			return -ENOMEM;
+		if (IS_ERR(session)) {
+			return PTR_ERR(session);

This doesn't compile, so I take back that kudo ;-\

Quoted 1 line

I'm fixing this by removing that needless '{'.

tools/perf/bench/synthesize.c +1 -1
index e39daa609db2ed9b..b2924e3181dc3844 100644
@@ -162,7 +162,7 @@ static int do_run_multi_threaded(struct target *target,
 	init_stats(&event_stats);
 	for (i = 0; i < multi_iterations; i++) {
 		session = perf_session__new(NULL, false, NULL);
-		if (IS_ERR(session)) {
+		if (IS_ERR(session))
 			return PTR_ERR(session);
 
 		atomic_set(&event_count, 0);
author
#5 lore raw
Quoted 13 lines · Arnaldo Carvalho de Melo

Em Thu, Sep 03, 2020 at 03:54:51PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 12 lines

Em Thu, Sep 03, 2020 at 03:53:01PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 9 lines

Em Wed, Sep 02, 2020 at 10:05:26PM +0800, YueHaibing escreveu:

Quoted 6 lines

In case of error, the function perf_session__new() returns ERR_PTR() and never returns NULL. The NULL test in the return value check should be replaced with IS_ERR()

Fixes 13edc237200c ("perf bench: Add a multi-threaded synthesize benchmark")

Thanks, applied, kudos for adding the Fixes: tag, appreciated!

But...

OOps, sorry for this, I'll pay attention next time.

Quoted 38 lines
Quoted 21 lines
Quoted 5 lines
Quoted 5 lines
 
---
 tools/perf/bench/synthesize.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 12 lines

tools/perf/bench/synthesize.c static int do_run_multi_threaded(struct target *target, · line 166

Quoted 12 lines
tools/perf/bench/synthesize.c +2 -2
index 8d624aea1c5e..e39daa609db2 100644
@@ -162,8 +162,8 @@ static int do_run_multi_threaded(struct target *target,
 	init_stats(&event_stats);
 	for (i = 0; i < multi_iterations; i++) {
 		session = perf_session__new(NULL, false, NULL);
-		if (!session)
-			return -ENOMEM;
+		if (IS_ERR(session)) {
+			return PTR_ERR(session);

This doesn't compile, so I take back that kudo ;-\

I'm fixing this by removing that needless '{'.

tools/perf/bench/synthesize.c +1 -1
index e39daa609db2ed9b..b2924e3181dc3844 100644
@@ -162,7 +162,7 @@ static int do_run_multi_threaded(struct target *target,
 	init_stats(&event_stats);
 	for (i = 0; i < multi_iterations; i++) {
 		session = perf_session__new(NULL, false, NULL);
-		if (IS_ERR(session)) {
+		if (IS_ERR(session))
 			return PTR_ERR(session);
 
 		atomic_set(&event_count, 0);

.

#6 lore raw

Em Fri, Sep 04, 2020 at 09:25:02PM +0800, Yuehaibing escreveu:

Quoted 10 lines · Arnaldo Carvalho de Melo
Quoted 7 lines

Em Thu, Sep 03, 2020 at 03:54:51PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Fixes 13edc237200c ("perf bench: Add a multi-threaded synthesize benchmark")

Thanks, applied, kudos for adding the Fixes: tag, appreciated!

But...

OOps, sorry for this, I'll pay attention next time.

Thanks!

- Arnaldo

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 9 lines

Review static int do_run_multi_threaded(struct target *target, · line 166

Quoted 9 lines

+++ b/tools/perf/bench/synthesize.c

(quoted diff) +2 -2
@@ -162,8 +162,8 @@ static int do_run_multi_threaded(struct target *target,
 	init_stats(&event_stats);
 	for (i = 0; i < multi_iterations; i++) {
 		session = perf_session__new(NULL, false, NULL);
-		if (!session)
-			return -ENOMEM;
+		if (IS_ERR(session)) {
+			return PTR_ERR(session);

This doesn't compile, so I take back that kudo ;-\

I'm fixing this by removing that needless '{'.