ipc: message queue receive cleanup
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / ipc / compat.c
index ad9518eb26e06e648c6044b95de41d39e9b076d0..eb3ea16d2d1dd351d69c27156d096578188938f8 100644 (file)
@@ -306,6 +306,20 @@ static long do_compat_semctl(int first, int second, int third, u32 pad)
        return err;
 }
 
+long compat_do_msg_fill(void __user *dest, struct msg_msg *msg, size_t bufsz)
+{
+       struct compat_msgbuf __user *msgp = dest;
+       size_t msgsz;
+
+       if (put_user(msg->m_type, &msgp->mtype))
+               return -EFAULT;
+
+       msgsz = (bufsz > msg->m_ts) ? msg->m_ts : bufsz;
+       if (store_msg(msgp->mtext, msg, msgsz))
+               return -EFAULT;
+       return msgsz;
+}
+
 #ifdef CONFIG_ARCH_WANT_OLD_COMPAT_IPC
 long compat_sys_semctl(int first, int second, int third, void __user *uptr)
 {
@@ -337,10 +351,6 @@ long compat_sys_msgsnd(int first, int second, int third, void __user *uptr)
 long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
                           int version, void __user *uptr)
 {
-       struct compat_msgbuf __user *up;
-       long type;
-       int err;
-
        if (first < 0)
                return -EINVAL;
        if (second < 0)
@@ -348,23 +358,14 @@ long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
 
        if (!version) {
                struct compat_ipc_kludge ipck;
-               err = -EINVAL;
                if (!uptr)
-                       goto out;
-               err = -EFAULT;
+                       return -EINVAL;
                if (copy_from_user (&ipck, uptr, sizeof(ipck)))
-                       goto out;
+                       return -EFAULT;
                uptr = compat_ptr(ipck.msgp);
                msgtyp = ipck.msgtyp;
        }
-       up = uptr;
-       err = do_msgrcv(first, &type, up->mtext, second, msgtyp, third);
-       if (err < 0)
-               goto out;
-       if (put_user(type, &up->mtype))
-               err = -EFAULT;
-out:
-       return err;
+       return do_msgrcv(first, uptr, second, msgtyp, third, compat_do_msg_fill);
 }
 #else
 long 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,
 long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp,
                       compat_ssize_t msgsz, long msgtyp, int msgflg)
 {
-       long err, mtype;
-
-       err =  do_msgrcv(msqid, &mtype, msgp->mtext, (ssize_t)msgsz, msgtyp, msgflg);
-       if (err < 0)
-               goto out;
-
-       if (put_user(mtype, &msgp->mtype))
-               err = -EFAULT;
- out:
-       return err;
+       return do_msgrcv(msqid, msgp, (ssize_t)msgsz, msgtyp, msgflg,
+                        compat_do_msg_fill);
 }
 #endif