]> git.karo-electronics.de Git - linux-beck.git/commitdiff
cgroup: update and fix parsing of "cgroup.subtree_control"
authorTejun Heo <tj@kernel.org>
Tue, 13 May 2014 16:10:59 +0000 (12:10 -0400)
committerTejun Heo <tj@kernel.org>
Tue, 13 May 2014 16:10:59 +0000 (12:10 -0400)
I was confused that strsep() was equivalent to strtok_r() in skipping
over consecutive delimiters.  strsep() just splits at the first
occurrence of one of the delimiters which makes the parsing very
inflexible, which makes allowing multiple whitespace chars as
delimters kinda moot.  Let's just be consistently strict and require
list of tokens separated by spaces.  This is what
Documentation/cgroups/unified-hierarchy.txt describes too.

Also, parsing may access beyond the end of the string if the string
ends with spaces or is zero-length.  Make sure it skips zero-length
tokens.  Note that this also ensures that the parser doesn't puke on
multiple consecutive spaces.

v2: Add zero-length token skipping.

v3: Added missing space after "==".  Spotted by Li.

Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
kernel/cgroup.c

index 35daf892b6e6a2d078144833c8fe267a713a7b0e..250def0694b48cfa926b9c1d53a6455e3800e14d 100644 (file)
@@ -2542,11 +2542,13 @@ static int cgroup_subtree_control_write(struct cgroup_subsys_state *dummy_css,
        int ssid, ret;
 
        /*
-        * Parse input - white space separated list of subsystem names
-        * prefixed with either + or -.
+        * Parse input - space separated list of subsystem names prefixed
+        * with either + or -.
         */
        p = buffer;
-       while ((tok = strsep(&p, " \t\n"))) {
+       while ((tok = strsep(&p, " "))) {
+               if (tok[0] == '\0')
+                       continue;
                for_each_subsys(ss, ssid) {
                        if (ss->disabled || strcmp(tok + 1, ss->name))
                                continue;