summaryrefslogtreecommitdiff
path: root/nuttx/sched
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-12-06 07:18:48 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-12-06 07:18:48 -0600
commit8a9a1e6cb28f4813fec9955b76bb6aa08d777d33 (patch)
tree7b5c7f12f2be9e8d83fd2b958eb33ca451545aa5 /nuttx/sched
parentc0be986a323c2103e51428200c7492d505dbfe6d (diff)
downloadnuttx-8a9a1e6cb28f4813fec9955b76bb6aa08d777d33.tar.gz
nuttx-8a9a1e6cb28f4813fec9955b76bb6aa08d777d33.tar.bz2
nuttx-8a9a1e6cb28f4813fec9955b76bb6aa08d777d33.zip
In message queue created return ENOSPC error if size exceeds the configured size of pre-allocatd messages; Use ENOSPC vs ENOMEM per OpenGroup.org. From Pierre-Noel Bouteville
Diffstat (limited to 'nuttx/sched')
-rw-r--r--nuttx/sched/mqueue/mq_msgqalloc.c32
-rw-r--r--nuttx/sched/mqueue/mqueue.h2
2 files changed, 20 insertions, 14 deletions
diff --git a/nuttx/sched/mqueue/mq_msgqalloc.c b/nuttx/sched/mqueue/mq_msgqalloc.c
index 6b5cea76e..280f1f182 100644
--- a/nuttx/sched/mqueue/mq_msgqalloc.c
+++ b/nuttx/sched/mqueue/mq_msgqalloc.c
@@ -40,6 +40,7 @@
#include <nuttx/config.h>
#include <mqueue.h>
+#include <assert.h>
#include <nuttx/kmalloc.h>
#include <nuttx/sched.h>
@@ -77,16 +78,16 @@
*
* Description:
* This function implements a part of the POSIX message queue open logic.
- * It allocates and initializes a structu mqueue_inode_s structure.
+ * It allocates and initializes a struct mqueue_inode_s structure.
*
* Parameters:
* mode - mode_t value is ignored
* attr - The mq_maxmsg attribute is used at the time that the message
* queue is created to determine the maximum number of
- * messages that may be placed in the message queue.
+ * messages that may be placed in the message queue.
*
* Return Value:
- * The allocated and initalized message queue structure or NULL in the
+ * The allocated and initialized message queue structure or NULL in the
* event of a failure.
*
****************************************************************************/
@@ -96,9 +97,21 @@ FAR struct mqueue_inode_s *mq_msgqalloc(mode_t mode,
{
FAR struct mqueue_inode_s *msgq;
+ /* Check if the caller is attempting to allocate a message for messages
+ * larger than the configured maximum message size.
+ */
+
+ DEBUGASSERT(!attr || attr->mq_msgsize <= MQ_MAX_BYTES);
+ if (attr && attr->mq_msgsize > MQ_MAX_BYTES)
+ {
+ return NULL;
+ }
+
/* Allocate memory for the new message queue. */
- msgq = (FAR struct mqueue_inode_s*)kmm_zalloc(sizeof(struct mqueue_inode_s));
+ msgq = (FAR struct mqueue_inode_s*)
+ kmm_zalloc(sizeof(struct mqueue_inode_s));
+
if (msgq)
{
/* Initialize the new named message queue */
@@ -106,15 +119,8 @@ FAR struct mqueue_inode_s *mq_msgqalloc(mode_t mode,
sq_init(&msgq->msglist);
if (attr)
{
- msgq->maxmsgs = (int16_t)attr->mq_maxmsg;
- if (attr->mq_msgsize <= MQ_MAX_BYTES)
- {
- msgq->maxmsgsize = (int16_t)attr->mq_msgsize;
- }
- else
- {
- msgq->maxmsgsize = MQ_MAX_BYTES;
- }
+ msgq->maxmsgs = (int16_t)attr->mq_maxmsg;
+ msgq->maxmsgsize = (int16_t)attr->mq_msgsize;
}
else
{
diff --git a/nuttx/sched/mqueue/mqueue.h b/nuttx/sched/mqueue/mqueue.h
index 03bc8d050..bd771e140 100644
--- a/nuttx/sched/mqueue/mqueue.h
+++ b/nuttx/sched/mqueue/mqueue.h
@@ -98,7 +98,7 @@ struct mqueue_msg_s
#else
uint16_t msglen; /* Message data length */
#endif
- uint8_t mail[MQ_MAX_BYTES]; /* Message data */
+ char mail[MQ_MAX_BYTES]; /* Message data */
};
/****************************************************************************