Skip to contentSkip to conversation

perf cgroup: Make evlist__find_cgroup() more compact

tip:perf/urgent tip-bot for Arnaldo Carvalho de Melo 1 participant 1 message Jun 7, 2018 perf events

lore
Share & tools
lore
#0 lore raw
Commit-ID:  5dbe23e8772299f227f1ac974752bc853e9814bb
Gitweb:     https://git.kernel.org/tip/5dbe23e8772299f227f1ac974752bc853e9814bb
Author:     Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Thu, 24 May 2018 11:29:07 -0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 4 Jun 2018 10:28:50 -0300

perf cgroup: Make evlist__find_cgroup() more compact

By taking advantage that __get() routines return the pointer to the object for which a reference count is being get.

---
 tools/perf/util/cgroup.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
tools/perf/util/cgroup.c +3 -6
index decb91f9da82..ccd02634a616 100644
@@ -93,20 +93,17 @@ static int open_cgroup(const char *name)
 static struct cgroup *evlist__find_cgroup(struct perf_evlist *evlist, const char *str)
 {
 	struct perf_evsel *counter;
-	struct cgroup *cgrp = NULL;
 	/*
 	 * check if cgrp is already defined, if so we reuse it
 	 */
 	evlist__for_each_entry(evlist, counter) {
 		if (!counter->cgrp)
 			continue;
-		if (!strcmp(counter->cgrp->name, str)) {
-			cgrp = cgroup__get(counter->cgrp);
-			break;
-		}
+		if (!strcmp(counter->cgrp->name, str))
+			return cgroup__get(counter->cgrp);
 	}
 
-	return cgrp;
+	return NULL;
 }
 
 static struct cgroup *cgroup__new(const char *name)