Skip to content

Commit 063e7d7

Browse files
committed
[nrf fromlist] soc: nordic: dmm: Add lock around sys_heap operations
sys_heap alloc and free are not thread safe so lock is needed to prevent data corruption. Upstream PR #: 90280 Signed-off-by: Krzysztof Chruściński <[email protected]>
1 parent d6abfeb commit 063e7d7

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

soc/nordic/common/dmm.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,24 @@ static size_t dmm_heap_size_get(struct dmm_heap *dh)
113113

114114
static void *dmm_buffer_alloc(struct dmm_heap *dh, size_t length)
115115
{
116+
void *ret;
117+
uint32_t key;
118+
116119
length = ROUND_UP(length, dh->region->dt_align);
117-
return sys_heap_aligned_alloc(&dh->heap, dh->region->dt_align, length);
120+
121+
key = irq_lock();
122+
ret = sys_heap_aligned_alloc(&dh->heap, dh->region->dt_align, length);
123+
irq_unlock(key);
124+
125+
return ret;
118126
}
119127

120128
static void dmm_buffer_free(struct dmm_heap *dh, void *buffer)
121129
{
130+
uint32_t key = irq_lock();
131+
122132
sys_heap_free(&dh->heap, buffer);
133+
irq_unlock(key);
123134
}
124135

125136
int dmm_buffer_out_prepare(void *region, void const *user_buffer, size_t user_length,

0 commit comments

Comments
 (0)