Skip to contentSkip to conversation

perf cgroup: Introduce cgroup__new() out of open coded equivalent

tip:perf/core tip-bot for Arnaldo Carvalho de Melo 1 participant 1 message Mar 9, 2018 perf events

lore
Share & tools
lore
#0 lore raw
Commit-ID:  923a0fb332f8ee49b063df07129b2686f78ec9c3
Gitweb:     https://git.kernel.org/tip/923a0fb332f8ee49b063df07129b2686f78ec9c3
Author:     Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Tue, 6 Mar 2018 10:33:04 -0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 7 Mar 2018 10:22:25 -0300

perf cgroup: Introduce cgroup__new() out of open coded equivalent

To follow the namespacing convention in tools/perf.

---
 tools/perf/util/cgroup.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)
tools/perf/util/cgroup.c +20 -10
index 84dfc34a6d0f..26a837037797 100644
@@ -109,6 +109,25 @@ static struct cgroup *evlist__find_cgroup(struct perf_evlist *evlist, char *str)
 	return cgrp;
 }
 
+static struct cgroup *cgroup__new(char *name)
+{
+	struct cgroup *cgroup = zalloc(sizeof(*cgroup));
+
+	if (cgroup != NULL) {
+		cgroup->name = name;
+		refcount_set(&cgroup->refcnt, 1);
+
+		cgroup->fd = open_cgroup(name);
+		if (cgroup->fd == -1)
+			goto out_err;
+	}
+
+	return cgroup;
+out_err:
+	free(cgroup);
+	return NULL;
+}
+
 static int add_cgroup(struct perf_evlist *evlist, char *str)
 {
 	struct perf_evsel *counter;
@@ -116,18 +135,9 @@ static int add_cgroup(struct perf_evlist *evlist, char *str)
 	int n;
 
 	if (!cgrp) {
-		cgrp = zalloc(sizeof(*cgrp));
+		cgrp = cgroup__new(str);
 		if (!cgrp)
 			return -1;
-
-		cgrp->name = str;
-		refcount_set(&cgrp->refcnt, 1);
-
-		cgrp->fd = open_cgroup(str);
-		if (cgrp->fd == -1) {
-			free(cgrp);
-			return -1;
-		}
 	}
 
 	/*