Skip to content

Commit c71d2ea

Browse files
committed
kernel: queue: guard heap functions with CONFIG_KERNEL_MEM_POOL
Wrap alloc_node struct, k_free, z_thread_malloc calls, and k_queue_alloc_append/prepend APIs with #ifdef CONFIG_KERNEL_MEM_POOL. This allows building with CONFIG_KERNEL_MEM_POOL=n without requiring stub implementations for heap functions. The alloc-based queue APIs are only meaningful when heap is available. Signed-off-by: GridPoint <engineering@gridpoint.com>
1 parent f1b6403 commit c71d2ea

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

kernel/queue.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@
2222
#include <kernel_internal.h>
2323
#include <zephyr/sys/check.h>
2424

25+
#ifdef CONFIG_KERNEL_MEM_POOL
2526
struct alloc_node {
2627
sys_sfnode_t node;
2728
void *data;
2829
};
30+
#endif /* CONFIG_KERNEL_MEM_POOL */
2931

3032
void *z_queue_node_peek(sys_sfnode_t *node, bool needs_free)
3133
{
3234
void *ret;
3335

36+
#ifdef CONFIG_KERNEL_MEM_POOL
3437
if ((node != NULL) && (sys_sfnode_flags_get(node) != (uint8_t)0)) {
3538
/* If the flag is set, then the enqueue operation for this item
3639
* did a behind-the scenes memory allocation of an alloc_node
@@ -44,7 +47,9 @@ void *z_queue_node_peek(sys_sfnode_t *node, bool needs_free)
4447
if (needs_free) {
4548
k_free(anode);
4649
}
47-
} else {
50+
} else
51+
#endif /* CONFIG_KERNEL_MEM_POOL */
52+
{
4853
/* Data was directly placed in the queue, the first word
4954
* reserved for the linked list. User mode isn't allowed to
5055
* do this, although it can get data sent this way.
@@ -153,6 +158,7 @@ static int32_t queue_insert(struct k_queue *queue, void *prev, void *data,
153158
}
154159

155160
/* Only need to actually allocate if no threads are pending */
161+
#ifdef CONFIG_KERNEL_MEM_POOL
156162
if (alloc) {
157163
struct alloc_node *anode;
158164

@@ -164,7 +170,10 @@ static int32_t queue_insert(struct k_queue *queue, void *prev, void *data,
164170
anode->data = data;
165171
sys_sfnode_init(&anode->node, 0x1);
166172
data = anode;
167-
} else {
173+
} else
174+
#endif /* CONFIG_KERNEL_MEM_POOL */
175+
{
176+
ARG_UNUSED(alloc);
168177
sys_sfnode_init(data, 0x0);
169178
}
170179

@@ -212,6 +221,7 @@ void k_queue_prepend(struct k_queue *queue, void *data)
212221
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_queue, prepend, queue);
213222
}
214223

224+
#ifdef CONFIG_KERNEL_MEM_POOL
215225
int32_t z_impl_k_queue_alloc_append(struct k_queue *queue, void *data)
216226
{
217227
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_queue, alloc_append, queue);
@@ -253,6 +263,7 @@ static inline int32_t z_vrfy_k_queue_alloc_prepend(struct k_queue *queue,
253263
}
254264
#include <zephyr/syscalls/k_queue_alloc_prepend_mrsh.c>
255265
#endif /* CONFIG_USERSPACE */
266+
#endif /* CONFIG_KERNEL_MEM_POOL */
256267

257268
int k_queue_append_list(struct k_queue *queue, void *head, void *tail)
258269
{

0 commit comments

Comments
 (0)