From 5e61c06c85fb6810d2e6923716d73e6db3d1e684 Mon Sep 17 00:00:00 2001 From: Ibrahim Abdalkader Date: Tue, 9 Dec 2025 17:25:29 +0100 Subject: [PATCH] drivers: i3c: Use kernel heap for allocations Use the kernel heap instead of the libc heap, improving security and consistency. Signed-off-by: Ibrahim Abdalkader --- drivers/i3c/Kconfig | 8 ++++++++ drivers/i3c/i3c_common.c | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/i3c/Kconfig b/drivers/i3c/Kconfig index 3c08e726b88..a5dd8a253d1 100644 --- a/drivers/i3c/Kconfig +++ b/drivers/i3c/Kconfig @@ -58,6 +58,14 @@ config I3C_TARGET_BUFFER_MODE help This is an option to enable buffer mode. +config HEAP_MEM_POOL_ADD_SIZE_I3C + int "Heap memory pool size for I3C" + default 48 + depends on I3C_CONTROLLER && I3C_TARGET + help + The size of the memory pool used by I3C. Used only for + DEFTGTS (Define List of Targets) CCC (Common Command Code). + menuconfig I3C_USE_IBI bool "Use In-Band Interrupt (IBI)" default y diff --git a/drivers/i3c/i3c_common.c b/drivers/i3c/i3c_common.c index ba543ec0a7a..1a4ce9d3cc8 100644 --- a/drivers/i3c/i3c_common.c +++ b/drivers/i3c/i3c_common.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -1327,7 +1328,7 @@ int i3c_bus_deftgts(const struct device *dev) } /* Allocate memory for the struct with enough space for the targets */ - deftgts = malloc(data_len); + deftgts = k_malloc(data_len); if (!deftgts) { return -ENOMEM; } @@ -1371,7 +1372,7 @@ int i3c_bus_deftgts(const struct device *dev) ret = i3c_ccc_do_deftgts_all(dev, deftgts); - free(deftgts); + k_free(deftgts); return ret; }