Merge branch 'merge' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc
[deliverable/linux.git] / ipc / msg.c
index 7a20536c3a50698c4c88f5ae15e86003df6f75c3..950572f9d7963858d46e01998fea00e14024f26b 100644 (file)
--- a/ipc/msg.c
+++ b/ipc/msg.c
@@ -770,16 +770,10 @@ static long do_msg_fill(void __user *dest, struct msg_msg *msg, size_t bufsz)
 }
 
 #ifdef CONFIG_CHECKPOINT_RESTORE
-static inline struct msg_msg *fill_copy(unsigned long copy_nr,
-                                       unsigned long msg_nr,
-                                       struct msg_msg *msg,
-                                       struct msg_msg *copy)
-{
-       if (copy_nr == msg_nr)
-               return copy_msg(msg, copy);
-       return NULL;
-}
-
+/*
+ * This function creates new kernel message structure, large enough to store
+ * bufsz message bytes.
+ */
 static inline struct msg_msg *prepare_copy(void __user *buf, size_t bufsz,
                                           int msgflg, long *msgtyp,
                                           unsigned long *copy_number)
@@ -803,8 +797,13 @@ static inline void free_copy(struct msg_msg *copy)
                free_msg(copy);
 }
 #else
-#define prepare_copy(buf, sz, msgflg, msgtyp, copy_nr) ERR_PTR(-ENOSYS)
-#define fill_copy(copy_nr, msg_nr, msg, copy)          NULL
+static inline struct msg_msg *prepare_copy(void __user *buf, size_t bufsz,
+                                          int msgflg, long *msgtyp,
+                                          unsigned long *copy_number)
+{
+       return ERR_PTR(-ENOSYS);
+}
+
 static inline void free_copy(struct msg_msg *copy)
 {
 }
@@ -819,7 +818,7 @@ long do_msgrcv(int msqid, void __user *buf, size_t bufsz, long msgtyp,
        int mode;
        struct ipc_namespace *ns;
        struct msg_msg *copy = NULL;
-       unsigned long __maybe_unused copy_number;
+       unsigned long copy_number = 0;
 
        if (msqid < 0 || (long) bufsz < 0)
                return -EINVAL;
@@ -861,11 +860,16 @@ long do_msgrcv(int msqid, void __user *buf, size_t bufsz, long msgtyp,
                                                walk_msg->m_type != 1) {
                                        msgtyp = walk_msg->m_type - 1;
                                } else if (msgflg & MSG_COPY) {
-                                       msg = fill_copy(copy_number,
-                                                       msg_counter,
-                                                       walk_msg, copy);
-                                       if (msg)
+                                       if (copy_number == msg_counter) {
+                                               /*
+                                                * Found requested message.
+                                                * Copy it.
+                                                */
+                                               msg = copy_msg(msg, copy);
+                                               if (IS_ERR(msg))
+                                                       goto out_unlock;
                                                break;
+                                       }
                                } else
                                        break;
                                msg_counter++;
@@ -881,6 +885,10 @@ long do_msgrcv(int msqid, void __user *buf, size_t bufsz, long msgtyp,
                                msg = ERR_PTR(-E2BIG);
                                goto out_unlock;
                        }
+                       /*
+                        * If we are copying, then do not unlink message and do
+                        * not update queue parameters.
+                        */
                        if (msgflg & MSG_COPY)
                                goto out_unlock;
                        list_del(&msg->m_list);
This page took 0.02571 seconds and 5 git commands to generate.