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

ipc/mqueue.c: fix mq_open() return value

We return ENOMEM from mqueue_get_inode even when we have enough memory.
Namely in case the system rlimit of mqueue was reached.  This error
propagates to mq_queue and user sees the error unexpectedly.  So fix
this up to properly return EMFILE as described in the manpage:

	EMFILE The process already has the maximum number of files and
	       message queues open.

instead of:

	ENOMEM Insufficient memory.

With the previous patch we just switch to ERR_PTR/PTR_ERR/IS_ERR error
handling here.
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 04715206
...@@ -113,6 +113,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb, ...@@ -113,6 +113,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
{ {
struct user_struct *u = current_user(); struct user_struct *u = current_user();
struct inode *inode; struct inode *inode;
int ret = -ENOMEM;
inode = new_inode(sb); inode = new_inode(sb);
if (!inode) if (!inode)
...@@ -160,6 +161,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb, ...@@ -160,6 +161,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE)) { u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE)) {
spin_unlock(&mq_lock); spin_unlock(&mq_lock);
/* mqueue_evict_inode() releases info->messages */ /* mqueue_evict_inode() releases info->messages */
ret = -EMFILE;
goto out_inode; goto out_inode;
} }
u->mq_bytes += mq_bytes; u->mq_bytes += mq_bytes;
...@@ -179,7 +181,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb, ...@@ -179,7 +181,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
out_inode: out_inode:
iput(inode); iput(inode);
err: err:
return NULL; return ERR_PTR(ret);
} }
static int mqueue_fill_super(struct super_block *sb, void *data, int silent) static int mqueue_fill_super(struct super_block *sb, void *data, int silent)
...@@ -195,8 +197,8 @@ static int mqueue_fill_super(struct super_block *sb, void *data, int silent) ...@@ -195,8 +197,8 @@ static int mqueue_fill_super(struct super_block *sb, void *data, int silent)
inode = mqueue_get_inode(sb, ns, S_IFDIR | S_ISVTX | S_IRWXUGO, inode = mqueue_get_inode(sb, ns, S_IFDIR | S_ISVTX | S_IRWXUGO,
NULL); NULL);
if (!inode) { if (IS_ERR(inode)) {
error = -ENOMEM; error = PTR_ERR(inode);
goto out; goto out;
} }
...@@ -316,8 +318,8 @@ static int mqueue_create(struct inode *dir, struct dentry *dentry, ...@@ -316,8 +318,8 @@ static int mqueue_create(struct inode *dir, struct dentry *dentry,
spin_unlock(&mq_lock); spin_unlock(&mq_lock);
inode = mqueue_get_inode(dir->i_sb, ipc_ns, mode, attr); inode = mqueue_get_inode(dir->i_sb, ipc_ns, mode, attr);
if (!inode) { if (IS_ERR(inode)) {
error = -ENOMEM; error = PTR_ERR(inode);
spin_lock(&mq_lock); spin_lock(&mq_lock);
ipc_ns->mq_queues_count--; ipc_ns->mq_queues_count--;
goto out_unlock; goto out_unlock;
......
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