diff options
-rw-r--r-- | kernel/cgroup.c | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index ff7d642a070a..896e035eb6e4 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -2490,10 +2490,18 @@ static int cgroup_file_open(struct inode *inode, struct file *file) | |||
2490 | } | 2490 | } |
2491 | rcu_read_unlock(); | 2491 | rcu_read_unlock(); |
2492 | 2492 | ||
2493 | /* css should match @cfe->css, see cgroup_add_file() for details */ | 2493 | if (!css) |
2494 | if (!css || WARN_ON_ONCE(css != cfe->css)) | ||
2495 | return -ENODEV; | 2494 | return -ENODEV; |
2496 | 2495 | ||
2496 | /* | ||
2497 | * @cfe->css is used by read/write/close to determine the | ||
2498 | * associated css. @file->private_data would be a better place but | ||
2499 | * that's already used by seqfile. Multiple accessors may use it | ||
2500 | * simultaneously which is okay as the association never changes. | ||
2501 | */ | ||
2502 | WARN_ON_ONCE(cfe->css && cfe->css != css); | ||
2503 | cfe->css = css; | ||
2504 | |||
2497 | if (cft->read_map || cft->read_seq_string) { | 2505 | if (cft->read_map || cft->read_seq_string) { |
2498 | file->f_op = &cgroup_seqfile_operations; | 2506 | file->f_op = &cgroup_seqfile_operations; |
2499 | err = single_open(file, cgroup_seqfile_show, cfe); | 2507 | err = single_open(file, cgroup_seqfile_show, cfe); |
@@ -2772,18 +2780,6 @@ static int cgroup_add_file(struct cgroup *cgrp, struct cftype *cft) | |||
2772 | dentry->d_fsdata = cfe; | 2780 | dentry->d_fsdata = cfe; |
2773 | simple_xattrs_init(&cfe->xattrs); | 2781 | simple_xattrs_init(&cfe->xattrs); |
2774 | 2782 | ||
2775 | /* | ||
2776 | * cfe->css is used by read/write/close to determine the associated | ||
2777 | * css. file->private_data would be a better place but that's | ||
2778 | * already used by seqfile. Note that open will use the usual | ||
2779 | * cgroup_css() and css_tryget() to acquire the css and this | ||
2780 | * caching doesn't affect css lifetime management. | ||
2781 | */ | ||
2782 | if (cft->ss) | ||
2783 | cfe->css = cgroup_css(cgrp, cft->ss->subsys_id); | ||
2784 | else | ||
2785 | cfe->css = &cgrp->dummy_css; | ||
2786 | |||
2787 | mode = cgroup_file_mode(cft); | 2783 | mode = cgroup_file_mode(cft); |
2788 | error = cgroup_create_file(dentry, mode | S_IFREG, cgrp->root->sb); | 2784 | error = cgroup_create_file(dentry, mode | S_IFREG, cgrp->root->sb); |
2789 | if (!error) { | 2785 | if (!error) { |