Commit 876ede8b authored by Li Zefan's avatar Li Zefan Committed by Tejun Heo

cgroup: restructure the failure path in cgroup_write_event_control()

It uses a single label and checks the validity of each pointer. This
is err-prone, and actually we had a bug because one of the check was
insufficient.

Use multi lables as we do in other places.

v2:
- drop initializations of local variables.
Signed-off-by: default avatarLi Zefan <lizefan@huawei.com>
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
parent e14880f7
...@@ -3934,11 +3934,11 @@ static void cgroup_event_ptable_queue_proc(struct file *file, ...@@ -3934,11 +3934,11 @@ static void cgroup_event_ptable_queue_proc(struct file *file,
static int cgroup_write_event_control(struct cgroup *cgrp, struct cftype *cft, static int cgroup_write_event_control(struct cgroup *cgrp, struct cftype *cft,
const char *buffer) const char *buffer)
{ {
struct cgroup_event *event = NULL; struct cgroup_event *event;
struct cgroup *cgrp_cfile; struct cgroup *cgrp_cfile;
unsigned int efd, cfd; unsigned int efd, cfd;
struct file *efile = NULL; struct file *efile;
struct file *cfile = NULL; struct file *cfile;
char *endp; char *endp;
int ret; int ret;
...@@ -3964,31 +3964,31 @@ static int cgroup_write_event_control(struct cgroup *cgrp, struct cftype *cft, ...@@ -3964,31 +3964,31 @@ static int cgroup_write_event_control(struct cgroup *cgrp, struct cftype *cft,
efile = eventfd_fget(efd); efile = eventfd_fget(efd);
if (IS_ERR(efile)) { if (IS_ERR(efile)) {
ret = PTR_ERR(efile); ret = PTR_ERR(efile);
goto fail; goto out_kfree;
} }
event->eventfd = eventfd_ctx_fileget(efile); event->eventfd = eventfd_ctx_fileget(efile);
if (IS_ERR(event->eventfd)) { if (IS_ERR(event->eventfd)) {
ret = PTR_ERR(event->eventfd); ret = PTR_ERR(event->eventfd);
goto fail; goto out_put_efile;
} }
cfile = fget(cfd); cfile = fget(cfd);
if (!cfile) { if (!cfile) {
ret = -EBADF; ret = -EBADF;
goto fail; goto out_put_eventfd;
} }
/* the process need read permission on control file */ /* the process need read permission on control file */
/* 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 = inode_permission(file_inode(cfile), MAY_READ); ret = inode_permission(file_inode(cfile), MAY_READ);
if (ret < 0) if (ret < 0)
goto fail; goto out_put_cfile;
event->cft = __file_cft(cfile); event->cft = __file_cft(cfile);
if (IS_ERR(event->cft)) { if (IS_ERR(event->cft)) {
ret = PTR_ERR(event->cft); ret = PTR_ERR(event->cft);
goto fail; goto out_put_cfile;
} }
/* /*
...@@ -3998,18 +3998,18 @@ static int cgroup_write_event_control(struct cgroup *cgrp, struct cftype *cft, ...@@ -3998,18 +3998,18 @@ static int cgroup_write_event_control(struct cgroup *cgrp, struct cftype *cft,
cgrp_cfile = __d_cgrp(cfile->f_dentry->d_parent); cgrp_cfile = __d_cgrp(cfile->f_dentry->d_parent);
if (cgrp_cfile != cgrp) { if (cgrp_cfile != cgrp) {
ret = -EINVAL; ret = -EINVAL;
goto fail; goto out_put_cfile;
} }
if (!event->cft->register_event || !event->cft->unregister_event) { if (!event->cft->register_event || !event->cft->unregister_event) {
ret = -EINVAL; ret = -EINVAL;
goto fail; goto out_put_cfile;
} }
ret = event->cft->register_event(cgrp, event->cft, ret = event->cft->register_event(cgrp, event->cft,
event->eventfd, buffer); event->eventfd, buffer);
if (ret) if (ret)
goto fail; goto out_put_cfile;
efile->f_op->poll(efile, &event->pt); efile->f_op->poll(efile, &event->pt);
...@@ -4029,16 +4029,13 @@ static int cgroup_write_event_control(struct cgroup *cgrp, struct cftype *cft, ...@@ -4029,16 +4029,13 @@ static int cgroup_write_event_control(struct cgroup *cgrp, struct cftype *cft,
return 0; return 0;
fail: out_put_cfile:
if (cfile) fput(cfile);
fput(cfile); out_put_eventfd:
eventfd_ctx_put(event->eventfd);
if (event && event->eventfd && !IS_ERR(event->eventfd)) out_put_efile:
eventfd_ctx_put(event->eventfd); fput(efile);
out_kfree:
if (!IS_ERR_OR_NULL(efile))
fput(efile);
kfree(event); kfree(event);
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment