Skip to content

Commit c8308b1

Browse files
andre-rosaAl Viro
authored andcommitted
mqueue: remove unneeded info->messages initialization
... and abort earlier if we couldn't allocate the message pointers array, avoiding the u->mq_bytes accounting logic. It reduces code size: text data bss dec hex filename 9949 72 16 10037 2735 ipc/mqueue-BEFORE.o 9941 72 16 10029 272d 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 4294a8e commit c8308b1

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

‎ipc/mqueue.c‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
134134
init_waitqueue_head(&info->wait_q);
135135
INIT_LIST_HEAD(&info->e_wait_q[0].list);
136136
INIT_LIST_HEAD(&info->e_wait_q[1].list);
137-
info->messages = NULL;
138137
info->notify_owner = NULL;
139138
info->qsize = 0;
140139
info->user = NULL; /* set when all is ok */
@@ -146,6 +145,10 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
146145
info->attr.mq_msgsize = attr->mq_msgsize;
147146
}
148147
mq_msg_tblsz = info->attr.mq_maxmsg * sizeof(struct msg_msg *);
148+
info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
149+
if (!info->messages)
150+
goto out_inode;
151+
149152
mq_bytes = (mq_msg_tblsz +
150153
(info->attr.mq_maxmsg * info->attr.mq_msgsize));
151154

@@ -154,18 +157,12 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
154157
u->mq_bytes + mq_bytes >
155158
p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
156159
spin_unlock(&mq_lock);
160+
kfree(info->messages);
157161
goto out_inode;
158162
}
159163
u->mq_bytes += mq_bytes;
160164
spin_unlock(&mq_lock);
161165

162-
info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
163-
if (!info->messages) {
164-
spin_lock(&mq_lock);
165-
u->mq_bytes -= mq_bytes;
166-
spin_unlock(&mq_lock);
167-
goto out_inode;
168-
}
169166
/* all is ok */
170167
info->user = get_uid(u);
171168
} else if (S_ISDIR(mode)) {

0 commit comments

Comments
 (0)