Commit 04715206 authored by Jiri Slaby's avatar Jiri Slaby Committed by Linus Torvalds

ipc/mqueue.c: refactor failure handling

If new_inode fails to allocate an inode we need only to return with
NULL.  But now we test the opposite and have all the work in a nested
block.  So do the opposite to save one indentation level (and remove
unnecessary line breaks).

This is only a preparation/cleanup for the next patch where we fix up
return values from mqueue_get_inode.
Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
Cc: Manfred Spraul <manfred@colorfullife.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent a64a26e8
...@@ -115,69 +115,70 @@ static struct inode *mqueue_get_inode(struct super_block *sb, ...@@ -115,69 +115,70 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
struct inode *inode; struct inode *inode;
inode = new_inode(sb); inode = new_inode(sb);
if (inode) { if (!inode)
inode->i_ino = get_next_ino(); goto err;
inode->i_mode = mode;
inode->i_uid = current_fsuid();
inode->i_gid = current_fsgid();
inode->i_mtime = inode->i_ctime = inode->i_atime =
CURRENT_TIME;
if (S_ISREG(mode)) { inode->i_ino = get_next_ino();
struct mqueue_inode_info *info; inode->i_mode = mode;
struct task_struct *p = current; inode->i_uid = current_fsuid();
unsigned long mq_bytes, mq_msg_tblsz; inode->i_gid = current_fsgid();
inode->i_mtime = inode->i_ctime = inode->i_atime = CURRENT_TIME;
inode->i_fop = &mqueue_file_operations;
inode->i_size = FILENT_SIZE; if (S_ISREG(mode)) {
/* mqueue specific info */ struct mqueue_inode_info *info;
info = MQUEUE_I(inode); struct task_struct *p = current;
spin_lock_init(&info->lock); unsigned long mq_bytes, mq_msg_tblsz;
init_waitqueue_head(&info->wait_q);
INIT_LIST_HEAD(&info->e_wait_q[0].list); inode->i_fop = &mqueue_file_operations;
INIT_LIST_HEAD(&info->e_wait_q[1].list); inode->i_size = FILENT_SIZE;
info->notify_owner = NULL; /* mqueue specific info */
info->qsize = 0; info = MQUEUE_I(inode);
info->user = NULL; /* set when all is ok */ spin_lock_init(&info->lock);
memset(&info->attr, 0, sizeof(info->attr)); init_waitqueue_head(&info->wait_q);
info->attr.mq_maxmsg = ipc_ns->mq_msg_max; INIT_LIST_HEAD(&info->e_wait_q[0].list);
info->attr.mq_msgsize = ipc_ns->mq_msgsize_max; INIT_LIST_HEAD(&info->e_wait_q[1].list);
if (attr) { info->notify_owner = NULL;
info->attr.mq_maxmsg = attr->mq_maxmsg; info->qsize = 0;
info->attr.mq_msgsize = attr->mq_msgsize; info->user = NULL; /* set when all is ok */
} memset(&info->attr, 0, sizeof(info->attr));
mq_msg_tblsz = info->attr.mq_maxmsg * sizeof(struct msg_msg *); info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL); info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
if (!info->messages) if (attr) {
goto out_inode; info->attr.mq_maxmsg = attr->mq_maxmsg;
info->attr.mq_msgsize = attr->mq_msgsize;
mq_bytes = (mq_msg_tblsz + }
(info->attr.mq_maxmsg * info->attr.mq_msgsize)); mq_msg_tblsz = info->attr.mq_maxmsg * sizeof(struct msg_msg *);
info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
spin_lock(&mq_lock); if (!info->messages)
if (u->mq_bytes + mq_bytes < u->mq_bytes || goto out_inode;
u->mq_bytes + mq_bytes >
task_rlimit(p, RLIMIT_MSGQUEUE)) {
spin_unlock(&mq_lock);
/* mqueue_evict_inode() releases info->messages */
goto out_inode;
}
u->mq_bytes += mq_bytes;
spin_unlock(&mq_lock);
/* all is ok */ mq_bytes = (mq_msg_tblsz +
info->user = get_uid(u); (info->attr.mq_maxmsg * info->attr.mq_msgsize));
} else if (S_ISDIR(mode)) {
inc_nlink(inode); spin_lock(&mq_lock);
/* Some things misbehave if size == 0 on a directory */ if (u->mq_bytes + mq_bytes < u->mq_bytes ||
inode->i_size = 2 * DIRENT_SIZE; u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE)) {
inode->i_op = &mqueue_dir_inode_operations; spin_unlock(&mq_lock);
inode->i_fop = &simple_dir_operations; /* mqueue_evict_inode() releases info->messages */
goto out_inode;
} }
u->mq_bytes += mq_bytes;
spin_unlock(&mq_lock);
/* all is ok */
info->user = get_uid(u);
} else if (S_ISDIR(mode)) {
inc_nlink(inode);
/* Some things misbehave if size == 0 on a directory */
inode->i_size = 2 * DIRENT_SIZE;
inode->i_op = &mqueue_dir_inode_operations;
inode->i_fop = &simple_dir_operations;
} }
return inode; return inode;
out_inode: out_inode:
iput(inode); iput(inode);
err:
return NULL; return NULL;
} }
......
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