Commit c8308b1c91056b09e96d40dbde4880ea685c377e
Committed by
Al Viro
1 parent
4294a8eedb
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>
Showing 1 changed file with 5 additions and 8 deletions Side-by-side Diff
ipc/mqueue.c
... | ... | @@ -134,7 +134,6 @@ |
134 | 134 | init_waitqueue_head(&info->wait_q); |
135 | 135 | INIT_LIST_HEAD(&info->e_wait_q[0].list); |
136 | 136 | INIT_LIST_HEAD(&info->e_wait_q[1].list); |
137 | - info->messages = NULL; | |
138 | 137 | info->notify_owner = NULL; |
139 | 138 | info->qsize = 0; |
140 | 139 | info->user = NULL; /* set when all is ok */ |
... | ... | @@ -146,6 +145,10 @@ |
146 | 145 | info->attr.mq_msgsize = attr->mq_msgsize; |
147 | 146 | } |
148 | 147 | 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 | + | |
149 | 152 | mq_bytes = (mq_msg_tblsz + |
150 | 153 | (info->attr.mq_maxmsg * info->attr.mq_msgsize)); |
151 | 154 | |
152 | 155 | |
... | ... | @@ -154,18 +157,12 @@ |
154 | 157 | u->mq_bytes + mq_bytes > |
155 | 158 | p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) { |
156 | 159 | spin_unlock(&mq_lock); |
160 | + kfree(info->messages); | |
157 | 161 | goto out_inode; |
158 | 162 | } |
159 | 163 | u->mq_bytes += mq_bytes; |
160 | 164 | spin_unlock(&mq_lock); |
161 | 165 | |
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 | - } | |
169 | 166 | /* all is ok */ |
170 | 167 | info->user = get_uid(u); |
171 | 168 | } else if (S_ISDIR(mode)) { |