diff options
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r-- | kernel/cgroup.c | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 356c40d5d20a..f4c4dce9558f 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -829,6 +829,39 @@ enum cgroup_filetype { | |||
829 | FILE_TASKLIST, | 829 | FILE_TASKLIST, |
830 | }; | 830 | }; |
831 | 831 | ||
832 | static ssize_t cgroup_write_uint(struct cgroup *cont, struct cftype *cft, | ||
833 | struct file *file, | ||
834 | const char __user *userbuf, | ||
835 | size_t nbytes, loff_t *unused_ppos) | ||
836 | { | ||
837 | char buffer[64]; | ||
838 | int retval = 0; | ||
839 | u64 val; | ||
840 | char *end; | ||
841 | |||
842 | if (!nbytes) | ||
843 | return -EINVAL; | ||
844 | if (nbytes >= sizeof(buffer)) | ||
845 | return -E2BIG; | ||
846 | if (copy_from_user(buffer, userbuf, nbytes)) | ||
847 | return -EFAULT; | ||
848 | |||
849 | buffer[nbytes] = 0; /* nul-terminate */ | ||
850 | |||
851 | /* strip newline if necessary */ | ||
852 | if (nbytes && (buffer[nbytes-1] == '\n')) | ||
853 | buffer[nbytes-1] = 0; | ||
854 | val = simple_strtoull(buffer, &end, 0); | ||
855 | if (*end) | ||
856 | return -EINVAL; | ||
857 | |||
858 | /* Pass to subsystem */ | ||
859 | retval = cft->write_uint(cont, cft, val); | ||
860 | if (!retval) | ||
861 | retval = nbytes; | ||
862 | return retval; | ||
863 | } | ||
864 | |||
832 | static ssize_t cgroup_common_file_write(struct cgroup *cont, | 865 | static ssize_t cgroup_common_file_write(struct cgroup *cont, |
833 | struct cftype *cft, | 866 | struct cftype *cft, |
834 | struct file *file, | 867 | struct file *file, |
@@ -886,10 +919,11 @@ static ssize_t cgroup_file_write(struct file *file, const char __user *buf, | |||
886 | 919 | ||
887 | if (!cft) | 920 | if (!cft) |
888 | return -ENODEV; | 921 | return -ENODEV; |
889 | if (!cft->write) | 922 | if (cft->write) |
890 | return -EINVAL; | 923 | return cft->write(cont, cft, file, buf, nbytes, ppos); |
891 | 924 | if (cft->write_uint) | |
892 | return cft->write(cont, cft, file, buf, nbytes, ppos); | 925 | return cgroup_write_uint(cont, cft, file, buf, nbytes, ppos); |
926 | return -EINVAL; | ||
893 | } | 927 | } |
894 | 928 | ||
895 | static ssize_t cgroup_read_uint(struct cgroup *cont, struct cftype *cft, | 929 | static ssize_t cgroup_read_uint(struct cgroup *cont, struct cftype *cft, |