mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-01 02:36:02 +00:00
memcg_write_event_control(): switch to CLASS(fd)
some reordering required - take both fdget() to the point before the allocations, with matching move of fdput() to the very end of failure exit(s); after that it converts trivially. simplify the cleanups that involve css_put(), while we are at it... Reviewed-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
66635b0776
commit
7133dd5ac6
@ -1911,8 +1911,6 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of,
|
|||||||
struct mem_cgroup_event *event;
|
struct mem_cgroup_event *event;
|
||||||
struct cgroup_subsys_state *cfile_css;
|
struct cgroup_subsys_state *cfile_css;
|
||||||
unsigned int efd, cfd;
|
unsigned int efd, cfd;
|
||||||
struct fd efile;
|
|
||||||
struct fd cfile;
|
|
||||||
struct dentry *cdentry;
|
struct dentry *cdentry;
|
||||||
const char *name;
|
const char *name;
|
||||||
char *endp;
|
char *endp;
|
||||||
@ -1936,6 +1934,12 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of,
|
|||||||
else
|
else
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
CLASS(fd, efile)(efd);
|
||||||
|
if (fd_empty(efile))
|
||||||
|
return -EBADF;
|
||||||
|
|
||||||
|
CLASS(fd, cfile)(cfd);
|
||||||
|
|
||||||
event = kzalloc(sizeof(*event), GFP_KERNEL);
|
event = kzalloc(sizeof(*event), GFP_KERNEL);
|
||||||
if (!event)
|
if (!event)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
@ -1946,20 +1950,13 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of,
|
|||||||
init_waitqueue_func_entry(&event->wait, memcg_event_wake);
|
init_waitqueue_func_entry(&event->wait, memcg_event_wake);
|
||||||
INIT_WORK(&event->remove, memcg_event_remove);
|
INIT_WORK(&event->remove, memcg_event_remove);
|
||||||
|
|
||||||
efile = fdget(efd);
|
|
||||||
if (!fd_file(efile)) {
|
|
||||||
ret = -EBADF;
|
|
||||||
goto out_kfree;
|
|
||||||
}
|
|
||||||
|
|
||||||
event->eventfd = eventfd_ctx_fileget(fd_file(efile));
|
event->eventfd = eventfd_ctx_fileget(fd_file(efile));
|
||||||
if (IS_ERR(event->eventfd)) {
|
if (IS_ERR(event->eventfd)) {
|
||||||
ret = PTR_ERR(event->eventfd);
|
ret = PTR_ERR(event->eventfd);
|
||||||
goto out_put_efile;
|
goto out_kfree;
|
||||||
}
|
}
|
||||||
|
|
||||||
cfile = fdget(cfd);
|
if (fd_empty(cfile)) {
|
||||||
if (!fd_file(cfile)) {
|
|
||||||
ret = -EBADF;
|
ret = -EBADF;
|
||||||
goto out_put_eventfd;
|
goto out_put_eventfd;
|
||||||
}
|
}
|
||||||
@ -1968,7 +1965,7 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of,
|
|||||||
/* AV: shouldn't we check that it's been opened for read instead? */
|
/* AV: shouldn't we check that it's been opened for read instead? */
|
||||||
ret = file_permission(fd_file(cfile), MAY_READ);
|
ret = file_permission(fd_file(cfile), MAY_READ);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out_put_cfile;
|
goto out_put_eventfd;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The control file must be a regular cgroup1 file. As a regular cgroup
|
* The control file must be a regular cgroup1 file. As a regular cgroup
|
||||||
@ -1977,7 +1974,7 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of,
|
|||||||
cdentry = fd_file(cfile)->f_path.dentry;
|
cdentry = fd_file(cfile)->f_path.dentry;
|
||||||
if (cdentry->d_sb->s_type != &cgroup_fs_type || !d_is_reg(cdentry)) {
|
if (cdentry->d_sb->s_type != &cgroup_fs_type || !d_is_reg(cdentry)) {
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto out_put_cfile;
|
goto out_put_eventfd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2010,7 +2007,7 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of,
|
|||||||
event->unregister_event = memsw_cgroup_usage_unregister_event;
|
event->unregister_event = memsw_cgroup_usage_unregister_event;
|
||||||
} else {
|
} else {
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto out_put_cfile;
|
goto out_put_eventfd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2022,11 +2019,9 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of,
|
|||||||
&memory_cgrp_subsys);
|
&memory_cgrp_subsys);
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
if (IS_ERR(cfile_css))
|
if (IS_ERR(cfile_css))
|
||||||
goto out_put_cfile;
|
goto out_put_eventfd;
|
||||||
if (cfile_css != css) {
|
if (cfile_css != css)
|
||||||
css_put(cfile_css);
|
goto out_put_css;
|
||||||
goto out_put_cfile;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = event->register_event(memcg, event->eventfd, buf);
|
ret = event->register_event(memcg, event->eventfd, buf);
|
||||||
if (ret)
|
if (ret)
|
||||||
@ -2037,23 +2032,14 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of,
|
|||||||
spin_lock_irq(&memcg->event_list_lock);
|
spin_lock_irq(&memcg->event_list_lock);
|
||||||
list_add(&event->list, &memcg->event_list);
|
list_add(&event->list, &memcg->event_list);
|
||||||
spin_unlock_irq(&memcg->event_list_lock);
|
spin_unlock_irq(&memcg->event_list_lock);
|
||||||
|
|
||||||
fdput(cfile);
|
|
||||||
fdput(efile);
|
|
||||||
|
|
||||||
return nbytes;
|
return nbytes;
|
||||||
|
|
||||||
out_put_css:
|
out_put_css:
|
||||||
css_put(css);
|
css_put(cfile_css);
|
||||||
out_put_cfile:
|
|
||||||
fdput(cfile);
|
|
||||||
out_put_eventfd:
|
out_put_eventfd:
|
||||||
eventfd_ctx_put(event->eventfd);
|
eventfd_ctx_put(event->eventfd);
|
||||||
out_put_efile:
|
|
||||||
fdput(efile);
|
|
||||||
out_kfree:
|
out_kfree:
|
||||||
kfree(event);
|
kfree(event);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user