Skip to contentSkip to conversation

perf: Fine-tuning for three function implementations

PATCH In review SF Markus Elfring 3 participants 11 messages Jan 23, 2017 – Jan 26, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover perf: Fine-tuning for three function implementations

From: Markus Elfring <[email protected]>
Date: Mon, 23 Jan 2017 16:08:21 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (4):
Delete an unnecessary check in try_to_find_absolute_address() Delete an unnecessary assignment in try_to_find_absolute_address() Move an error code assignment in __perf_session__set_tracepoints_handlers() Move an error code assignment in strlist__parse_list_entry()

 tools/perf/util/probe-event.c | 11 ++++-------
 tools/perf/util/session.c     |  6 +++---
 tools/perf/util/strlist.c     |  5 +++--
 3 files changed, 10 insertions(+), 12 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/4 perf probe: Delete an unnecessary check in try_to_find_absolute_address()

From: Markus Elfring <[email protected]>
Date: Mon, 23 Jan 2017 14:54:26 +0100

Remove a condition check which is unnecessary at the end because this source code place should usually only be reached with a non-zero pointer.

---
 tools/perf/util/probe-event.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
tools/perf/util/probe-event.c +2 -4
index d281ae2b54e8..6c7508337fe8 100644
@@ -2966,10 +2966,8 @@ static int try_to_find_absolute_address(struct perf_probe_event *pev,
 	return 1;
 
 errout:
-	if (*tevs) {
-		clear_probe_trace_events(*tevs, 1);
-		*tevs = NULL;
-	}
+	clear_probe_trace_events(*tevs, 1);
+	*tevs = NULL;
 	return err;
 }
 
Signature · 1 line
2.11.0
Acked-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] perf probe: Delete an unnecessary check in try_to_find_absolute_address()

Quoted 6 lines · On Mon, 23 Jan 2017 16:22:22 +0100 SF Markus Elfring…

From: Markus Elfring <[email protected]>
Date: Mon, 23 Jan 2017 14:54:26 +0100

Remove a condition check which is unnecessary at the end because this source code place should usually only be reached with a non-zero pointer.

Looks good to me :)

Thanks!

Quoted 26 lines
---
 tools/perf/util/probe-event.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
tools/perf/util/probe-event.c +2 -4
index d281ae2b54e8..6c7508337fe8 100644
@@ -2966,10 +2966,8 @@ static int try_to_find_absolute_address(struct perf_probe_event *pev,
 	return 1;
 
 errout:
-	if (*tevs) {
-		clear_probe_trace_events(*tevs, 1);
-		*tevs = NULL;
-	}
+	clear_probe_trace_events(*tevs, 1);
+	*tevs = NULL;
 	return err;
 }
 
Signature · 1 line
2.11.0
Signature · 1 line
Masami Hiramatsu <[email protected]>
#3 lore raw

[tip:perf/core] perf probe: Delete an unnecessary check in try_to_find_absolute_address()

In reply to SF Markus Elfring
perf probe: Delete an unnecessary check in try_to_find_absolute_address()
Commit-ID:  42e233cacc052bd545417c68155f2b9abd1bab72
Gitweb:     http://git.kernel.org/tip/42e233cacc052bd545417c68155f2b9abd1bab72
Author:     Markus Elfring <[email protected]>
AuthorDate: Mon, 23 Jan 2017 14:54:26 +0100
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 26 Jan 2017 11:42:55 -0300

perf probe: Delete an unnecessary check in try_to_find_absolute_address()

Remove a condition check which is unnecessary at the end because this source code place should usually only be reached with a non-zero pointer.

---
 tools/perf/util/probe-event.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
tools/perf/util/probe-event.c +2 -4
index 4a57c8a..cdfc468 100644
@@ -3004,10 +3004,8 @@ static int try_to_find_absolute_address(struct perf_probe_event *pev,
 	return 1;
 
 errout:
-	if (*tevs) {
-		clear_probe_trace_events(*tevs, 1);
-		*tevs = NULL;
-	}
+	clear_probe_trace_events(*tevs, 1);
+	*tevs = NULL;
 	return err;
 }
 
#4 lore raw

PATCH 2/4 perf probe: Delete an unnecessary assignment in try_to_find_absolute_address()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 23 Jan 2017 15:10:19 +0100

Remove an error code assignment which is redundant in an if branch for the handling of a memory allocation failure because the same value was set for the local variable "err" before.

---
 tools/perf/util/probe-event.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tools/perf/util/probe-event.c +2 -3
index 6c7508337fe8..5a34c93b818a 100644
@@ -2956,10 +2956,9 @@ static int try_to_find_absolute_address(struct perf_probe_event *pev,
 
 	tev->nargs = pev->nargs;
 	tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs);
-	if (!tev->args) {
-		err = -ENOMEM;
+	if (!tev->args)
 		goto errout;
-	}
+
 	for (i = 0; i < tev->nargs; i++)
 		copy_to_probe_trace_arg(&tev->args[i], &pev->args[i]);
 
Signature · 1 line
2.11.0
Acked-by on v1 2/4
#5 lore raw

Re: [PATCH 2/4] perf probe: Delete an unnecessary assignment in try_to_find_absolute_address()

Quoted 8 lines · On Mon, 23 Jan 2017 16:24:06 +0100 SF Markus Elfring…

From: Markus Elfring <[email protected]>
Date: Mon, 23 Jan 2017 15:10:19 +0100

Remove an error code assignment which is redundant in an if branch for the handling of a memory allocation failure because the same value was set for the local variable "err" before.

This looks good to me :)

Thanks!

Quoted 24 lines
---
 tools/perf/util/probe-event.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tools/perf/util/probe-event.c +2 -3
index 6c7508337fe8..5a34c93b818a 100644
@@ -2956,10 +2956,9 @@ static int try_to_find_absolute_address(struct perf_probe_event *pev,
 
 	tev->nargs = pev->nargs;
 	tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs);
-	if (!tev->args) {
-		err = -ENOMEM;
+	if (!tev->args)
 		goto errout;
-	}
+
 	for (i = 0; i < tev->nargs; i++)
 		copy_to_probe_trace_arg(&tev->args[i], &pev->args[i]);
 
Signature · 1 line
2.11.0
Signature · 1 line
Masami Hiramatsu <[email protected]>
#6 lore raw

[tip:perf/core] perf probe: Delete an unnecessary assignment in try_to_find_absolute_address()

In reply to SF Markus Elfring
perf probe: Delete an unnecessary assignment in try_to_find_absolute_address()
Commit-ID:  d1d0e29cb7d03a6019caa125e4c0288366a4f359
Gitweb:     http://git.kernel.org/tip/d1d0e29cb7d03a6019caa125e4c0288366a4f359
Author:     Markus Elfring <[email protected]>
AuthorDate: Mon, 23 Jan 2017 15:10:19 +0100
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 26 Jan 2017 11:42:56 -0300

perf probe: Delete an unnecessary assignment in try_to_find_absolute_address()

Remove an error code assignment which is redundant in an if branch for the handling of a memory allocation failure because the same value was set for the local variable "err" before.

---
 tools/perf/util/probe-event.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tools/perf/util/probe-event.c +2 -3
index cdfc468..ded1e7d 100644
@@ -2994,10 +2994,9 @@ static int try_to_find_absolute_address(struct perf_probe_event *pev,
 
 	tev->nargs = pev->nargs;
 	tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs);
-	if (!tev->args) {
-		err = -ENOMEM;
+	if (!tev->args)
 		goto errout;
-	}
+
 	for (i = 0; i < tev->nargs; i++)
 		copy_to_probe_trace_arg(&tev->args[i], &pev->args[i]);
 
#7 lore raw

PATCH 3/4 perf session: Move an error code assignment in __perf_session__set_tracepoints_handlers()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 23 Jan 2017 15:43:13 +0100

A local variable was set to an error code before a concrete error situation was detected. Thus move the corresponding assignment into an if branch to indicate a software failure there.

This issue was detected by using the Coccinelle software.

---
 tools/perf/util/session.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/util/session.c +3 -3
index f268201048a0..98605ad4affd 100644
@@ -2050,10 +2050,10 @@ int __perf_session__set_tracepoints_handlers(struct perf_session *session,
 		evsel = perf_evlist__find_tracepoint_by_name(session->evlist, assocs[i].name);
 		if (evsel = NULL)
 			continue;
-
-		err = -EEXIST;
-		if (evsel->handler != NULL)
+		if (evsel->handler) {
+			err = -EEXIST;
 			goto out;
+		}
 		evsel->handler = assocs[i].handler;
 	}
 
Signature · 1 line
2.11.0
#8 lore raw

Re: [PATCH 3/4] perf session: Move an error code assignment in __perf_session__set_tracepoints_handlers()

Quoted 21 lines · On Mon, 23 Jan 2017 16:25:23 +0100 SF Markus Elfring…

From: Markus Elfring <[email protected]>
Date: Mon, 23 Jan 2017 15:43:13 +0100

A local variable was set to an error code before a concrete error situation was detected. Thus move the corresponding assignment into an if branch to indicate a software failure there.

This issue was detected by using the Coccinelle software.

---
 tools/perf/util/session.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/util/session.c +0 -0
index f268201048a0..98605ad4affd 100644
@@ -2050,10 +2050,10 @@ int __perf_session__set_tracepoints_handlers(struct perf_session *session,
 		evsel = perf_evlist__find_tracepoint_by_name(session->evlist, assocs[i].name);
 		if (evsel = NULL)

tools/perf/util/session.c int __perf_session__set_tracepoints_handlers(struct perf_session *session, · line 2058

Quoted 10 lines
tools/perf/util/session.c +3 -3
 			continue;
-
-		err = -EEXIST;
-		if (evsel->handler != NULL)
+		if (evsel->handler) {
+			err = -EEXIST;
 			goto out;
+		}
 		evsel->handler = assocs[i].handler;
 	}

Hmm, if we cleanup this function, it might be better not to use goto as below.

int __perf_session__set_tracepoints_handlers(struct perf_session *session,
const struct perf_evsel_str_handler *assocs, size_t nr_assocs)

{
        struct perf_evsel *evsel;
        size_t i;
        int err = 0;

        for (i = 0; i < nr_assocs; i++) {
                /*
                 * Adding a handler for an event not in the session,
                 * just ignore it.
                 */
                evsel = perf_evlist__find_tracepoint_by_name(session->evlist, assocs[i].name);
                if (evsel = NULL)
                        continue;

                if (evsel->handler != NULL) {
                        err = -EEXIST;
                        break;
		}
                evsel->handler = assocs[i].handler;
        }

        return err;
}

Thank you,

Signature · 1 line
Masami Hiramatsu <[email protected]>
#9 lore raw

PATCH 4/4 perf strlist: Move an error code assignment in strlist__parse_list_entry()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 23 Jan 2017 15:56:31 +0100

A local variable was set to an error code before a concrete error situation was detected. Thus move the corresponding assignment into an if branch to indicate a software failure there.

This issue was detected by using the Coccinelle software.

---
 tools/perf/util/strlist.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/perf/util/strlist.c +3 -2
index 0d3dfcb919b4..a934be385a6d 100644
@@ -118,9 +118,10 @@ static int strlist__parse_list_entry(struct strlist *slist, const char *s,
 		return strlist__load(slist, s + 7);
 
 	if (subst_dir) {
-		err = -ENOMEM;
-		if (asprintf(&subst, "%s/%s", subst_dir, s) < 0)
+		if (asprintf(&subst, "%s/%s", subst_dir, s) < 0) {
+			err = -ENOMEM;
 			goto out;
+		}
 
 		if (access(subst, F_OK) = 0) {
 			err = strlist__load(slist, subst);
Signature · 1 line
2.11.0
Acked-by on v1 4/4
#10 lore raw

Re: [PATCH 4/4] perf strlist: Move an error code assignment in strlist__parse_list_entry()

Quoted 8 lines · On Mon, 23 Jan 2017 16:26:24 +0100 SF Markus Elfring…

From: Markus Elfring <[email protected]>
Date: Mon, 23 Jan 2017 15:56:31 +0100

A local variable was set to an error code before a concrete error situation was detected. Thus move the corresponding assignment into an if branch to indicate a software failure there.

This issue was detected by using the Coccinelle software.

Looks good to me.

Thanks!

Quoted 26 lines
---
 tools/perf/util/strlist.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/perf/util/strlist.c +3 -2
index 0d3dfcb919b4..a934be385a6d 100644
@@ -118,9 +118,10 @@ static int strlist__parse_list_entry(struct strlist *slist, const char *s,
 		return strlist__load(slist, s + 7);
 
 	if (subst_dir) {
-		err = -ENOMEM;
-		if (asprintf(&subst, "%s/%s", subst_dir, s) < 0)
+		if (asprintf(&subst, "%s/%s", subst_dir, s) < 0) {
+			err = -ENOMEM;
 			goto out;
+		}
 
 		if (access(subst, F_OK) = 0) {
 			err = strlist__load(slist, subst);
Signature · 1 line
2.11.0
Signature · 1 line
Masami Hiramatsu <[email protected]>