summaryrefslogtreecommitdiffstats
path: root/kernel/cgroup.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r--kernel/cgroup.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 678a22c75fdb..faf55f59646b 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -1811,11 +1811,17 @@ int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen)
int ret = -ENAMETOOLONG;
char *start;
+ if (!cgrp->parent) {
+ if (strlcpy(buf, "/", buflen) >= buflen)
+ return -ENAMETOOLONG;
+ return 0;
+ }
+
start = buf + buflen - 1;
*start = '\0';
rcu_read_lock();
- while (cgrp) {
+ do {
const char *name = cgroup_name(cgrp);
int len;
@@ -1824,15 +1830,12 @@ int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen)
goto out;
memcpy(start, name, len);
- if (!cgrp->parent)
- break;
-
if (--start < buf)
goto out;
*start = '/';
cgrp = cgrp->parent;
- }
+ } while (cgrp->parent);
ret = 0;
memmove(buf, start, buf + buflen - start);
out: