Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion zephyr/lib/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@ static const struct vmh_heap_config static_hp_buffers = {

Copy link

Copilot AI Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider adding a brief comment above this function explaining the one-time init guard and expected usage to improve maintainability.

Suggested change
/*
* Initializes the virtual heap if it has not already been initialized.
* The one-time initialization guard ensures that the heap is only
* initialized once during the system's lifetime. This function is
* registered as a SYS_INIT hook to run during the POST_KERNEL phase.
*/

Copilot uses AI. Check for mistakes.
static int virtual_heap_init(void)
{
virtual_buffers_heap = vmh_init_heap(&static_hp_buffers, false);
if (!virtual_buffers_heap)
Copy link

Copilot AI Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This guard is not thread-safe; concurrent calls may still race and initialize the heap multiple times. Consider using a mutex or atomic compare-and-swap to ensure only one initialization occurs.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false positive - calls to virtual_heap_init are serialized.

virtual_buffers_heap = vmh_init_heap(&static_hp_buffers, false);

if (!virtual_buffers_heap) {
tr_err(&zephyr_tr, "Unable to init virtual heap");
return -ENOMEM;
Expand Down
Loading