linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Question] About '(*idx)++' of perf_evsel__new_idx
@ 2017-01-30  2:53 Taeung Song
  2017-01-30 19:03 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 3+ messages in thread
From: Taeung Song @ 2017-01-30  2:53 UTC (permalink / raw)
  To: perf group; +Cc: Arnaldo Carvalho de Melo, Namhyung Kim

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-01-31  2:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-30  2:53 [Question] About '(*idx)++' of perf_evsel__new_idx Taeung Song
2017-01-30 19:03 ` Arnaldo Carvalho de Melo
2017-01-31  2:13   ` Taeung Song

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).