From 8bbe96313ad4535a2957503c11df1a5ece1b4ad6 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Tue, 1 Dec 2026 22:26:21 +0000 Subject: [PATCH 1/2] posix: provide the Zephyr assert macros from rtos/panic.h On Zephyr, rtos/panic.h includes , so code that includes it for assert() also gets __ASSERT() and __ASSERT_NO_MSG(). Include the stub from the host rtos/panic.h, so that the kernel code that is also built for the host can use the Zephyr macros without new includes. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- posix/include/rtos/panic.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/posix/include/rtos/panic.h b/posix/include/rtos/panic.h index 2ba24eed48bc..6310921d0ba3 100644 --- a/posix/include/rtos/panic.h +++ b/posix/include/rtos/panic.h @@ -49,4 +49,10 @@ void __panic(uint32_t p, const char *filename, uint32_t linenum) SOF_NORETURN; #define assert(cond) (void)((cond) || (sof_panic(SOF_IPC_PANIC_ASSERT), 0)) #endif +/* + * The Zephyr assert macros. On Zephyr, rtos/panic.h provides them through + * . + */ +#include + #endif /* __POSIX_RTOS_PANIC_H__ */ From 4d4fc696f37d06feffbfca84b28a7368e12c19ea Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Sat, 5 Dec 2026 12:00:37 +0000 Subject: [PATCH 2/2] kernel: use __ASSERT_NO_MSG() instead of assert() Kernel code uses the native Zephyr API, while user code, such as the audio modules, keeps the POSIX assert() so that it can be shared with POSIX programs. The kernel-only code that the Zephyr builds alone compile already uses __ASSERT_NO_MSG(). Convert the remaining kernel code, which is also built for the host: the IPC handlers, the IPC3 DAI code, the IPC4 notifications and the dummy DMA driver. The host provides the Zephyr assert macros through rtos/panic.h. On Zephyr, assert() is defined as __ASSERT_NO_MSG(). No lines are added or removed, so __LINE__ in verbose asserts does not change. No functional change. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- src/kernel/drivers/generic/dummy-dma.c | 2 +- src/kernel/ipc/ipc-common-kernel.c | 4 ++-- src/kernel/ipc/ipc3/dai.c | 2 +- src/kernel/ipc/ipc3/handler.c | 6 +++--- src/kernel/ipc/ipc4/handler-kernel.c | 4 ++-- src/kernel/ipc/ipc4/notification.c | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/kernel/drivers/generic/dummy-dma.c b/src/kernel/drivers/generic/dummy-dma.c index af5bfad70595..fca634596f4c 100644 --- a/src/kernel/drivers/generic/dummy-dma.c +++ b/src/kernel/drivers/generic/dummy-dma.c @@ -108,7 +108,7 @@ static ssize_t dummy_dma_copy_crt_elem(struct dma_chan_pdata *pdata, /* Perform the copy, being careful if we overflow the elem */ ret = memcpy_s((void *)wptr, remaining_size, (void *)rptr, copy_size); - assert(!ret); + __ASSERT_NO_MSG(!ret); /* On capture, writeback the host buffer (it may lie in a cached area). * On playback, also writeback because host.c does an invalidate to diff --git a/src/kernel/ipc/ipc-common-kernel.c b/src/kernel/ipc/ipc-common-kernel.c index 3263c63c1255..9bca568e3478 100644 --- a/src/kernel/ipc/ipc-common-kernel.c +++ b/src/kernel/ipc/ipc-common-kernel.c @@ -194,7 +194,7 @@ __cold void ipc_msg_send_direct(struct ipc_msg *msg, void *data) if (data && msg->tx_size > 0 && msg->tx_size <= SOF_IPC_MSG_MAX_SIZE && msg->tx_data != data) { ret = memcpy_s(msg->tx_data, msg->tx_size, data, msg->tx_size); - assert(!ret); + __ASSERT_NO_MSG(!ret); } ipc_platform_send_msg_direct(msg); @@ -214,7 +214,7 @@ void z_impl_ipc_msg_send(struct ipc_msg *msg, void *data, bool high_priority) if (data && (msg->tx_size > 0 && msg->tx_size <= SOF_IPC_MSG_MAX_SIZE) && msg->tx_data != data) { ret = memcpy_s(msg->tx_data, msg->tx_size, data, msg->tx_size); - assert(!ret); + __ASSERT_NO_MSG(!ret); } /* diff --git a/src/kernel/ipc/ipc3/dai.c b/src/kernel/ipc/ipc3/dai.c index 5b0efff590da..ab52c821306a 100644 --- a/src/kernel/ipc/ipc3/dai.c +++ b/src/kernel/ipc/ipc3/dai.c @@ -45,7 +45,7 @@ int dai_config_dma_channel(struct dai_data *dd, struct comp_dev *dev, const void int channel; int handshake; - assert(config); + __ASSERT_NO_MSG(config); switch (config->type) { case SOF_DAI_INTEL_SSP: diff --git a/src/kernel/ipc/ipc3/handler.c b/src/kernel/ipc/ipc3/handler.c index c4b9cbc70c25..8990171ecc77 100644 --- a/src/kernel/ipc/ipc3/handler.c +++ b/src/kernel/ipc/ipc3/handler.c @@ -83,18 +83,18 @@ LOG_MODULE_DECLARE(ipc, CONFIG_SOF_LOG_LEVEL); int ___ret; \ if (rx_size > tx->size) { \ ___ret = memcpy_s(rx, rx_size, tx, tx->size); \ - assert(!___ret); \ + __ASSERT_NO_MSG(!___ret); \ bzero((char *)rx + tx->size, rx_size - tx->size);\ tr_dbg(&ipc_tr, "ipc: hdr 0x%x rx (%zu) > tx (%d)",\ rx->cmd, rx_size, tx->size); \ } else if (tx->size > rx_size) { \ ___ret = memcpy_s(rx, rx_size, tx, rx_size); \ - assert(!___ret); \ + __ASSERT_NO_MSG(!___ret); \ tr_warn(&ipc_tr, "ipc: hdr 0x%x tx (%d) > rx (%zu)",\ rx->cmd, tx->size, rx_size); \ } else { \ ___ret = memcpy_s(rx, rx_size, tx, rx_size); \ - assert(!___ret); \ + __ASSERT_NO_MSG(!___ret); \ } \ } while (0) diff --git a/src/kernel/ipc/ipc4/handler-kernel.c b/src/kernel/ipc/ipc4/handler-kernel.c index cf9188850ed6..b5a9b5e47028 100644 --- a/src/kernel/ipc/ipc4/handler-kernel.c +++ b/src/kernel/ipc/ipc4/handler-kernel.c @@ -96,7 +96,7 @@ static inline void ipc4_send_reply(struct ipc4_message_reply *reply) /* copy the extension from the message reply */ reply->extension.dat = msg_reply.extension; ret = memcpy_s(ipc->comp_data, sizeof(*reply), reply, sizeof(*reply)); - assert(!ret); + __ASSERT_NO_MSG(!ret); } #else /* CONFIG_LIBRARY */ static inline struct ipc4_message_request *ipc4_get_message_request(void) @@ -339,7 +339,7 @@ __cold static int ipc4_module_process_d0ix(struct ipc4_message_request *ipc4) __cold static void ipc_sec_core_sync_boot(uint32_t core_id) { #ifdef CONFIG_SOF_USERSPACE_LL - assert(core_id != PLATFORM_PRIMARY_CORE_ID); + __ASSERT_NO_MSG(core_id != PLATFORM_PRIMARY_CORE_ID); ipc_user_wait_core_init(core_id); #endif diff --git a/src/kernel/ipc/ipc4/notification.c b/src/kernel/ipc/ipc4/notification.c index 196771ecc0c4..4ef4feaac428 100644 --- a/src/kernel/ipc/ipc4/notification.c +++ b/src/kernel/ipc/ipc4/notification.c @@ -73,7 +73,7 @@ bool z_impl_send_resource_notif(uint32_t resource_id, uint32_t event_type, * Using a data type that is not included in the event_data union. * Return true to prevent an infinite re-try loop in non-debug builds */ - assert(false); + __ASSERT_NO_MSG(false); return true; } }