[PATCH 5/5] ipc,msg: loosen check for full queue

From: Davidlohr Bueso
Date: Tue May 13 2014 - 16:28:19 EST


When sending a message, we must guarantee that there will be
enough room in the queue to add it, otherwise wait until space
becomes available -- which requires blocking the calling task.
Currently, this relies meeting both of the following conditions:

(i) The new msg size + current size is lower than the queue's max size.
(ii) The current amount of messages in the queue + 1 (this msg) is lower
than the queue's max size.

While (i) is obvious and well documented in the msgsnd(2) manpage, the
second one is far more ambiguous and does not serve the purpose, as we do
not control the amount of messages in the queue (unlike posix queues do).
Thus remove (ii) and loosen how we check for space.

Signed-off-by: Davidlohr Bueso <davidlohr@xxxxxx>
---
ipc/msg.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/ipc/msg.c b/ipc/msg.c
index 956cd65..7d267d0 100644
--- a/ipc/msg.c
+++ b/ipc/msg.c
@@ -658,10 +658,8 @@ long do_msgsnd(int msqid, long mtype, void __user *mtext,
if (err)
goto out_unlock0;

- if (msgsz + msq->q_cbytes <= msq->q_qbytes &&
- 1 + msq->q_qnum <= msq->q_qbytes) {
- break;
- }
+ if (msgsz + msq->q_cbytes <= msq->q_qbytes)
+ break; /* there is space in the queue for this msg */

/* queue full, wait: */
if (msgflg & IPC_NOWAIT) {
--
1.8.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/