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

Em Mon, Jan 30, 2017 at 11:53:18AM +0900, Taeung Song escreveu:
> 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'?

I think you're right and we should increment idx only if we manage to
create the evsel instance, no need for the else clause tho.

- Arnaldo

  reply	other threads:[~2017-01-30 19:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-30  2:53 [Question] About '(*idx)++' of perf_evsel__new_idx Taeung Song
2017-01-30 19:03 ` Arnaldo Carvalho de Melo [this message]
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=20170130190306.GC4546@kernel.org \
    --to=acme@kernel.org \
    --cc=arnaldo.melo@gmail.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=namhyung@kernel.org \
    --cc=taeung@kosslab.kr \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.