public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: SF Markus Elfring <elfring@users.sourceforge.net>
Cc: Adrian Hunter <adrian.hunter@intel.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	He Kuang <hekuang@huawei.com>, Ingo Molnar <mingo@redhat.com>,
	Jiri Olsa <jolsa@kernel.org>,
	Milian Wolff <milian.wolff@kdab.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>,
	Wang Nan <wangnan0@huawei.com>,
	LKML <linux-kernel@vger.kernel.org>,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH 3/4] perf session: Move an error code assignment in __perf_session__set_tracepoints_handlers()
Date: Tue, 24 Jan 2017 07:56:34 +0900	[thread overview]
Message-ID: <20170124075634.76af7bfb0dd7d074cb8dd682@kernel.org> (raw)
In-Reply-To: <b9ccdf98-e7a9-e4a2-67d7-24617d4b87a6@users.sourceforge.net>

On Mon, 23 Jan 2017 16:25:23 +0100
SF Markus Elfring <elfring@users.sourceforge.net> wrote:

> From: Markus Elfring <elfring@users.sourceforge.net>
> 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.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  tools/perf/util/session.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
> index f268201048a0..98605ad4affd 100644
> --- a/tools/perf/util/session.c
> +++ b/tools/perf/util/session.c
> @@ -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;
>  	}

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,



-- 
Masami Hiramatsu <mhiramat@kernel.org>

  reply	other threads:[~2017-01-23 22:56 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-23 15:20 [PATCH 0/4] perf: Fine-tuning for three function implementations SF Markus Elfring
2017-01-23 15:22 ` [PATCH 1/4] perf probe: Delete an unnecessary check in try_to_find_absolute_address() SF Markus Elfring
2017-01-23 22:48   ` Masami Hiramatsu
2017-01-26 15:28   ` [tip:perf/core] " tip-bot for Markus Elfring
2017-01-23 15:24 ` [PATCH 2/4] perf probe: Delete an unnecessary assignment " SF Markus Elfring
2017-01-23 22:47   ` Masami Hiramatsu
2017-01-26 15:29   ` [tip:perf/core] " tip-bot for Markus Elfring
2017-01-23 15:25 ` [PATCH 3/4] perf session: Move an error code assignment in __perf_session__set_tracepoints_handlers() SF Markus Elfring
2017-01-23 22:56   ` Masami Hiramatsu [this message]
2017-01-23 15:26 ` [PATCH 4/4] perf strlist: Move an error code assignment in strlist__parse_list_entry() SF Markus Elfring
2017-01-23 23:32   ` Masami Hiramatsu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170124075634.76af7bfb0dd7d074cb8dd682@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=elfring@users.sourceforge.net \
    --cc=hekuang@huawei.com \
    --cc=jolsa@kernel.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=milian.wolff@kdab.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=ravi.bangoria@linux.vnet.ibm.com \
    --cc=wangnan0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox