linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Taeung Song <taeung@kosslab.kr>
To: perf group <linux-perf-users@vger.kernel.org>
Cc: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>,
	Namhyung Kim <namhyung@kernel.org>
Subject: [Question] About '(*idx)++' of perf_evsel__new_idx
Date: Mon, 30 Jan 2017 11:53:18 +0900	[thread overview]
Message-ID: <1f6c94c2-1e9d-a85d-b4b6-ad47510d4d3f@kosslab.kr> (raw)

Hi, :)

Can I ask you one thing ?

I'm reading source code util/parse-event.c
Along the way, I wonder why increase idx before checking
whether 'evsel' is NULL or not ? (at 310,311 line number)


300 static struct perf_evsel *
301 __add_event(struct list_head *list, int *idx,
302             struct perf_event_attr *attr,
303             char *name, struct cpu_map *cpus,
304             struct list_head *config_terms)
305 {
306         struct perf_evsel *evsel;
307
308         event_attr_init(attr);
309
310         evsel = perf_evsel__new_idx(attr, (*idx)++);
311         if (!evsel)
312                 return NULL;
313
314         evsel->cpus     = cpu_map__get(cpus);
315         evsel->own_cpus = cpu_map__get(cpus);
316

IMHO, if 'evsel' isn't NULL, we can increase idx like below.

             evsel = perf_evsel__new_idx(attr, *idx);
             if (!evsel)
                     return NULL;
             else
                (*idx)++;

Is it wrong ? or is there other reason about increasing idx
before check 'evsel'?

Thanks,
Taeung

             reply	other threads:[~2017-01-30  3:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-30  2:53 Taeung Song [this message]
2017-01-30 19:03 ` [Question] About '(*idx)++' of perf_evsel__new_idx Arnaldo Carvalho de Melo
2017-01-31  2:13   ` Taeung Song

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=1f6c94c2-1e9d-a85d-b4b6-ad47510d4d3f@kosslab.kr \
    --to=taeung@kosslab.kr \
    --cc=arnaldo.melo@gmail.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=namhyung@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).