Skip to content

Commit 869acdb

Browse files
peter-mitsiskartben
authored andcommitted
kernel: Add CONFIG_MEM_SLAB_POINTER_VALIDATE
Makes the validation of both allocated memory slab pointer and the memory slab pointer to free configurable. Signed-off-by: Peter Mitsis <[email protected]>
1 parent f0516ea commit 869acdb

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

kernel/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,13 @@ config POLL
677677
concurrently, which can be either directly triggered or triggered by
678678
the availability of some kernel objects (semaphores and FIFOs).
679679

680+
config MEM_SLAB_POINTER_VALIDATE
681+
bool "Validate the memory slab pointer when allocating or freeing"
682+
default ASSERT
683+
help
684+
This enables additional runtime checks to validate the memory slab
685+
pointer during when allocating or freeing a memory slab.
686+
680687
config MEM_SLAB_TRACE_MAX_UTILIZATION
681688
bool "Getting maximum slab utilization"
682689
help

kernel/mem_slab.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ int k_mem_slab_init(struct k_mem_slab *slab, void *buffer,
206206

207207
static bool slab_ptr_is_good(struct k_mem_slab *slab, const void *ptr)
208208
{
209+
if (!IS_ENABLED(CONFIG_MEM_SLAB_POINTER_VALIDATE)) {
210+
return true;
211+
}
212+
209213
const char *p = ptr;
210214
ptrdiff_t offset = p - slab->buffer;
211215

0 commit comments

Comments
 (0)