perf: Fine-tuning for three function implementations
Subsystems (2)
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
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
@@ -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
PATCH 2/4 perf probe: Delete an unnecessary assignment in try_to_find_absolute_address()
In reply to SF Markus ElfringFrom: 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
@@ -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
PATCH 3/4 perf session: Move an error code assignment in __perf_session__set_tracepoints_handlers()
In reply to SF Markus ElfringFrom: 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
@@ -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
PATCH 4/4 perf strlist: Move an error code assignment in strlist__parse_list_entry()
In reply to SF Markus ElfringFrom: 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
@@ -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
Re: [PATCH 2/4] perf probe: Delete an unnecessary assignment in try_to_find_absolute_address()
In reply to SF Markus ElfringQuoted 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 +0100Remove 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.
Signed-off-by Markus Elfring <[email protected]>
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@@ -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]>
Re: [PATCH 1/4] perf probe: Delete an unnecessary check in try_to_find_absolute_address()
In reply to SF Markus ElfringQuoted 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 +0100Remove 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
Signed-off-by Markus Elfring <[email protected]>--- tools/perf/util/probe-event.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)tools/perf/util/probe-event.c +2
-4@@ -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]>
Re: [PATCH 3/4] perf session: Move an error code assignment in __perf_session__set_tracepoints_handlers()
In reply to SF Markus ElfringQuoted 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 +0100A 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.
Signed-off-by Markus Elfring <[email protected]>--- tools/perf/util/session.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)tools/perf/util/session.c +0
-0@@ -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
-3continue ; - - 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]>
Re: [PATCH 4/4] perf strlist: Move an error code assignment in strlist__parse_list_entry()
In reply to SF Markus ElfringQuoted 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 +0100A 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
Signed-off-by Markus Elfring <[email protected]>--- tools/perf/util/strlist.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)tools/perf/util/strlist.c +3
-2@@ -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]>
tip-bot for Markus Elfring
merge bot[tip:perf/core] perf probe: Delete an unnecessary assignment in try_to_find_absolute_address()
In reply to SF Markus Elfringperf 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
@@ -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]);
tip-bot for Markus Elfring
merge bot[tip:perf/core] perf probe: Delete an unnecessary check in try_to_find_absolute_address()
In reply to SF Markus Elfringperf 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
@@ -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; }