[tip:perf/core] perf evlist: Destructors should accept NULL

From: tip-bot for Arnaldo Carvalho de Melo
Date: Sun Jun 26 2016 - 06:53:24 EST


Commit-ID: 0b04b3dcdfb9aeb0e83c8ca322bf0830ee51ce38
Gitweb: http://git.kernel.org/tip/0b04b3dcdfb9aeb0e83c8ca322bf0830ee51ce38
Author: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
AuthorDate: Tue, 21 Jun 2016 18:15:45 -0300
Committer: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
CommitDate: Wed, 22 Jun 2016 10:01:48 -0300

perf evlist: Destructors should accept NULL

And do nothing, just like free(), to avoid having to test it in callers,
usually in error paths.

Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Cc: David Ahern <dsahern@xxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Masami Hiramatsu <mhiramat@xxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Wang Nan <wangnan0@xxxxxxxxxx>
Link: http://lkml.kernel.org/n/tip-mexbavy0ft387j5w89t365eu@xxxxxxxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/builtin-kvm.c | 3 +--
tools/perf/tests/event-times.c | 3 +--
tools/perf/tests/parse-no-sample-id-all.c | 3 +--
tools/perf/util/evlist.c | 3 +++
4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 6487c06..ad46e91 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1429,8 +1429,7 @@ out:
if (kvm->session)
perf_session__delete(kvm->session);
kvm->session = NULL;
- if (kvm->evlist)
- perf_evlist__delete(kvm->evlist);
+ perf_evlist__delete(kvm->evlist);

return err;
}
diff --git a/tools/perf/tests/event-times.c b/tools/perf/tests/event-times.c
index 95fb744..9f5698a 100644
--- a/tools/perf/tests/event-times.c
+++ b/tools/perf/tests/event-times.c
@@ -200,8 +200,7 @@ static int test_times(int (attach)(struct perf_evlist *),
count.ena, count.run);

out_err:
- if (evlist)
- perf_evlist__delete(evlist);
+ perf_evlist__delete(evlist);
return !err ? TEST_OK : TEST_FAIL;
}

diff --git a/tools/perf/tests/parse-no-sample-id-all.c b/tools/perf/tests/parse-no-sample-id-all.c
index 294c76b..81c6eea 100644
--- a/tools/perf/tests/parse-no-sample-id-all.c
+++ b/tools/perf/tests/parse-no-sample-id-all.c
@@ -44,8 +44,7 @@ static int process_events(union perf_event **events, size_t count)
for (i = 0; i < count && !err; i++)
err = process_event(&evlist, events[i]);

- if (evlist)
- perf_evlist__delete(evlist);
+ perf_evlist__delete(evlist);

return err;
}
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 1b918aa..fcb8f1f 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -127,6 +127,9 @@ void perf_evlist__exit(struct perf_evlist *evlist)

void perf_evlist__delete(struct perf_evlist *evlist)
{
+ if (evlist == NULL)
+ return;
+
perf_evlist__munmap(evlist);
perf_evlist__close(evlist);
cpu_map__put(evlist->cpus);