From: Paul Menage Currently res_counter_write() is a raw file handler even though it's ultimately taking a number, since in some cases it wants to pre-process the string when converting it to a number. This patch converts res_counter_write() from a raw file handler to a write_string() handler; this allows some of the boilerplate copying/locking/checking to be removed, and simplies the cleanup path, since these functions are now performed by the cgroups framework. Signed-off-by: Paul Menage Cc: Balbir Singh Signed-off-by: Andrew Morton --- mm/memrlimitcgroup.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff -puN mm/memrlimitcgroup.c~memrlimit-setup-the-memrlimit-controller-cgroup-files-convert-res_counter_write-to-be-a-cgroups-write_string-handler-memrlimitcgroup mm/memrlimitcgroup.c --- a/mm/memrlimitcgroup.c~memrlimit-setup-the-memrlimit-controller-cgroup-files-convert-res_counter_write-to-be-a-cgroups-write_string-handler-memrlimitcgroup +++ a/mm/memrlimitcgroup.c @@ -86,25 +86,12 @@ static u64 memrlimit_cgroup_read(struct cft->private); } -static int memrlimit_cgroup_write_strategy(char *buf, unsigned long long *tmp) -{ - *tmp = memparse(buf, &buf); - if (*buf != '\0') - return -EINVAL; - - *tmp = PAGE_ALIGN(*tmp); - return 0; -} - -static ssize_t memrlimit_cgroup_write(struct cgroup *cgrp, struct cftype *cft, - struct file *file, - const char __user *userbuf, - size_t nbytes, - loff_t *ppos) +static int memrlimit_cgroup_write(struct cgroup *cgrp, struct cftype *cft, + const char *buffer) { return res_counter_write(&memrlimit_cgroup_from_cgrp(cgrp)->as_res, - cft->private, userbuf, nbytes, ppos, - memrlimit_cgroup_write_strategy); + cft->private, buffer, + res_counter_memparse_write_strategy); } static struct cftype memrlimit_cgroup_files[] = { @@ -116,7 +103,7 @@ static struct cftype memrlimit_cgroup_fi { .name = "limit_in_bytes", .private = RES_LIMIT, - .write = memrlimit_cgroup_write, + .write_string = memrlimit_cgroup_write, .read_u64 = memrlimit_cgroup_read, }, { _