Skip to content

Commit 04db0dd

Browse files
andre-rosaAl Viro
authored andcommitted
mqueue: simplify do_open() error handling
It reduces code size: text data bss dec hex filename 9925 72 16 10013 271d ipc/mqueue-BEFORE.o 9885 72 16 9973 26f5 ipc/mqueue-AFTER.o Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 8834cf7 commit 04db0dd

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

‎ipc/mqueue.c‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -657,24 +657,28 @@ static struct file *do_create(struct ipc_namespace *ipc_ns, struct dentry *dir,
657657
static struct file *do_open(struct ipc_namespace *ipc_ns,
658658
struct dentry *dentry, int oflag)
659659
{
660+
int ret;
660661
const struct cred *cred = current_cred();
661662

662663
static const int oflag2acc[O_ACCMODE] = { MAY_READ, MAY_WRITE,
663664
MAY_READ | MAY_WRITE };
664665

665666
if ((oflag & O_ACCMODE) == (O_RDWR | O_WRONLY)) {
666-
dput(dentry);
667-
mntput(ipc_ns->mq_mnt);
668-
return ERR_PTR(-EINVAL);
667+
ret = -EINVAL;
668+
goto err;
669669
}
670670

671671
if (inode_permission(dentry->d_inode, oflag2acc[oflag & O_ACCMODE])) {
672-
dput(dentry);
673-
mntput(ipc_ns->mq_mnt);
674-
return ERR_PTR(-EACCES);
672+
ret = -EACCES;
673+
goto err;
675674
}
676675

677676
return dentry_open(dentry, ipc_ns->mq_mnt, oflag, cred);
677+
678+
err:
679+
dput(dentry);
680+
mntput(ipc_ns->mq_mnt);
681+
return ERR_PTR(ret);
678682
}
679683

680684
SYSCALL_DEFINE4(mq_open, const char __user *, u_name, int, oflag, mode_t, mode,

0 commit comments

Comments
 (0)