Skip to content

Commit

Permalink
portability cmsis_rtosv2: Check return of k_mem_slab_init()
Browse files Browse the repository at this point in the history
Instead of trusting blindly that k_mem_slab_init()
will succeed, let's check it, and handle failures
appropriately.
Otherwise, a buffer of garbage will be passed
around, leading to misterious failures later on.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
  • Loading branch information
aescolar authored and fabiobaltieri committed Jun 20, 2023
1 parent 5850636 commit e59f6a8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion subsys/portability/cmsis_rtos_v2/mempool.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@ osMemoryPoolId_t osMemoryPoolNew(uint32_t block_count, uint32_t block_size,
mslab->is_dynamic_allocation = FALSE;
}

k_mem_slab_init(&mslab->z_mslab, mslab->pool, block_size, block_count);
int rc = k_mem_slab_init(&mslab->z_mslab, mslab->pool, block_size, block_count);

if (rc != 0) {
k_mem_slab_free(&cv2_mem_slab, (void *) &mslab);
if (attr->mp_mem == NULL) {
k_free(mslab->pool);
}
return NULL;
}

if (attr->name == NULL) {
strncpy(mslab->name, init_mslab_attrs.name,
Expand Down

0 comments on commit e59f6a8

Please sign in to comment.