Skip to content

Commit

Permalink
cmsis: resolve undefined reference to k_calloc()
Browse files Browse the repository at this point in the history
When no heap has been configured, osMessageQueueNew() will no
longer include a call to k_calloc() (which needs the heap).
In such a configuration, if osMessageQueueNew() indicates that
the buffer must be allocated, it will fail and return NULL.

Fixes zephyrproject-rtos#61196

Signed-off-by: Peter Mitsis <[email protected]>
  • Loading branch information
peter-mitsis authored and carlescufi committed Oct 25, 2023
1 parent e364f29 commit 467ce89
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions subsys/portability/cmsis_rtos_v2/msgq.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,17 @@ osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size,
CONFIG_CMSIS_V2_MSGQ_MAX_DYNAMIC_SIZE,
"message queue size exceeds dynamic maximum");

#if (CONFIG_HEAP_MEM_POOL_SIZE > 0)
msgq->pool = k_calloc(msg_count, msg_size);
if (msgq->pool == NULL) {
k_mem_slab_free(&cv2_msgq_slab, (void *)msgq);
return NULL;
}
msgq->is_dynamic_allocation = TRUE;
#else
k_mem_slab_free(&cv2_msgq_slab, (void *)msgq);
return NULL;
#endif
} else {
msgq->pool = attr->mq_mem;
msgq->is_dynamic_allocation = FALSE;
Expand Down

0 comments on commit 467ce89

Please sign in to comment.