aboutsummaryrefslogtreecommitdiffstats
path: root/ipc/compat.c
diff options
context:
space:
mode:
authorStanislav Kinsbursky <skinsbursky@parallels.com>2013-01-04 18:34:52 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-01-04 19:11:45 -0500
commitf9dd87f4738c7555aca2cdf8cb2b2326cafb0cad (patch)
tree4fb581910eaee4309ae6befeef8c4f921b274c5d /ipc/compat.c
parent03f595668017f1a1fb971c02fc37140bc6e7bb1c (diff)
ipc: message queue receive cleanup
Move all message related manipulation into one function msg_fill(). Actually, two functions because of the compat one. [akpm@linux-foundation.org: checkpatch fixes] Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com> Cc: Serge Hallyn <serge.hallyn@canonical.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Pavel Emelyanov <xemul@parallels.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Cc: Michael Kerrisk <mtk.manpages@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'ipc/compat.c')
-rw-r--r--ipc/compat.c45
1 files changed, 19 insertions, 26 deletions
diff --git a/ipc/compat.c b/ipc/compat.c
index ad9518eb26e0..eb3ea16d2d1d 100644
--- a/ipc/compat.c
+++ b/ipc/compat.c
@@ -306,6 +306,20 @@ static long do_compat_semctl(int first, int second, int third, u32 pad)
306 return err; 306 return err;
307} 307}
308 308
309long compat_do_msg_fill(void __user *dest, struct msg_msg *msg, size_t bufsz)
310{
311 struct compat_msgbuf __user *msgp = dest;
312 size_t msgsz;
313
314 if (put_user(msg->m_type, &msgp->mtype))
315 return -EFAULT;
316
317 msgsz = (bufsz > msg->m_ts) ? msg->m_ts : bufsz;
318 if (store_msg(msgp->mtext, msg, msgsz))
319 return -EFAULT;
320 return msgsz;
321}
322
309#ifdef CONFIG_ARCH_WANT_OLD_COMPAT_IPC 323#ifdef CONFIG_ARCH_WANT_OLD_COMPAT_IPC
310long compat_sys_semctl(int first, int second, int third, void __user *uptr) 324long compat_sys_semctl(int first, int second, int third, void __user *uptr)
311{ 325{
@@ -337,10 +351,6 @@ long compat_sys_msgsnd(int first, int second, int third, void __user *uptr)
337long compat_sys_msgrcv(int first, int second, int msgtyp, int third, 351long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
338 int version, void __user *uptr) 352 int version, void __user *uptr)
339{ 353{
340 struct compat_msgbuf __user *up;
341 long type;
342 int err;
343
344 if (first < 0) 354 if (first < 0)
345 return -EINVAL; 355 return -EINVAL;
346 if (second < 0) 356 if (second < 0)
@@ -348,23 +358,14 @@ long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
348 358
349 if (!version) { 359 if (!version) {
350 struct compat_ipc_kludge ipck; 360 struct compat_ipc_kludge ipck;
351 err = -EINVAL;
352 if (!uptr) 361 if (!uptr)
353 goto out; 362 return -EINVAL;
354 err = -EFAULT;
355 if (copy_from_user (&ipck, uptr, sizeof(ipck))) 363 if (copy_from_user (&ipck, uptr, sizeof(ipck)))
356 goto out; 364 return -EFAULT;
357 uptr = compat_ptr(ipck.msgp); 365 uptr = compat_ptr(ipck.msgp);
358 msgtyp = ipck.msgtyp; 366 msgtyp = ipck.msgtyp;
359 } 367 }
360 up = uptr; 368 return do_msgrcv(first, uptr, second, msgtyp, third, compat_do_msg_fill);
361 err = do_msgrcv(first, &type, up->mtext, second, msgtyp, third);
362 if (err < 0)
363 goto out;
364 if (put_user(type, &up->mtype))
365 err = -EFAULT;
366out:
367 return err;
368} 369}
369#else 370#else
370long compat_sys_semctl(int semid, int semnum, int cmd, int arg) 371long compat_sys_semctl(int semid, int semnum, int cmd, int arg)
@@ -385,16 +386,8 @@ long compat_sys_msgsnd(int msqid, struct compat_msgbuf __user *msgp,
385long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp, 386long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp,
386 compat_ssize_t msgsz, long msgtyp, int msgflg) 387 compat_ssize_t msgsz, long msgtyp, int msgflg)
387{ 388{
388 long err, mtype; 389 return do_msgrcv(msqid, msgp, (ssize_t)msgsz, msgtyp, msgflg,
389 390 compat_do_msg_fill);
390 err = do_msgrcv(msqid, &mtype, msgp->mtext, (ssize_t)msgsz, msgtyp, msgflg);
391 if (err < 0)
392 goto out;
393
394 if (put_user(mtype, &msgp->mtype))
395 err = -EFAULT;
396 out:
397 return err;
398} 391}
399#endif 392#endif
400 393