lib: cmsis_rtos_v2: Message queue checks

Added some additional checks when creating a message queue to ensure the
size of the queue does not exceed the size of the buffer passed in via
the optional attributes.

Added a new Kconfig option to limit the maximum size of a message queue
dynamically allocated on the heap.

Added a check to ensure the heap is at least large enough to hold a
maximum size dynamically allocated queue.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
This commit is contained in:
Carlos Stuart 2019-02-06 08:12:28 +00:00 committed by Anas Nashif
commit 17db516069
2 changed files with 18 additions and 0 deletions

View file

@ -68,6 +68,12 @@ config CMSIS_V2_MSGQ_MAX_COUNT
help
Mention maximum number of message queues in CMSIS RTOS V2 compliant application.
config CMSIS_V2_MSGQ_MAX_DYNAMIC_SIZE
int "Maximum dynamic message queue size in CMSIS RTOS V2 application"
default 0
help
Mention maximum dynamic size of message queues in CMSIS RTOS V2 compliant application.
config CMSIS_V2_EVT_FLAGS_MAX_COUNT
int "Maximum event flags count in CMSIS RTOS V2 application"
default 5

View file

@ -27,10 +27,18 @@ osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size,
{
struct cv2_msgq *msgq;
BUILD_ASSERT_MSG(CONFIG_HEAP_MEM_POOL_SIZE >=
CONFIG_CMSIS_V2_MSGQ_MAX_DYNAMIC_SIZE,
"heap must be configured to be at least the max dynamic size");
if (k_is_in_isr()) {
return NULL;
}
if ((attr != NULL) && (attr->mq_size < msg_count * msg_size)) {
return NULL;
}
if (attr == NULL) {
attr = &init_msgq_attrs;
}
@ -42,6 +50,10 @@ osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size,
}
if (attr->mq_mem == NULL) {
__ASSERT((msg_count * msg_size) <=
CONFIG_CMSIS_V2_MSGQ_MAX_DYNAMIC_SIZE,
"message queue size exceeds dynamic maximum");
msgq->pool = k_calloc(msg_count, msg_size);
if (msgq->pool == NULL) {
k_mem_slab_free(&cv2_msgq_slab, (void *) &msgq);