Skip to content

kernel: use __ASSERT_NO_MSG() instead of assert() - #11597

Draft
lgirdwood wants to merge 2 commits into
thesofproject:mainfrom
lgirdwood:topic/zn-rtos-assert-shared
Draft

lgirdwood wants to merge 2 commits into
thesofproject:mainfrom
lgirdwood:topic/zn-rtos-assert-shared

Conversation

@lgirdwood

@lgirdwood lgirdwood commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Use the Zephyr __ASSERT_NO_MSG() instead of assert() in the kernel code that is also built for the host. Part of #11517 (step 6).

Reworked after review: 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 earlier version of this PR also converted the user code; that part is dropped.

Patches

  1. posix: the host rtos/panic.h includes the <zephyr/sys/__assert.h> stub, as rtos/panic.h gets the Zephyr macros through <zephyr/kernel.h> on Zephyr. The kernel code that is also built for the host then needs no new includes.
  2. kernel: assert() → __ASSERT_NO_MSG() in the remaining kernel code (9 sites): the IPC handlers (ipc-common-kernel.c, IPC3 handler.c, IPC4 handler-kernel.c), the IPC3 DAI code, the IPC4 notifications and the dummy DMA driver. No lines are added or removed, so __LINE__ in verbose asserts does not change. The kernel-only code that only the Zephyr builds compile was converted in zephyr: use the Zephyr assert and panic macros in kernel-only code #11572.

Not in this PR

User code (src/audio, src/ipc, src/lib, src/module, src/samples and the shared headers in src/include) keeps assert().

Functional change

None on Zephyr, where assert() is defined as __ASSERT_NO_MSG(). On the host, these kernel asserts always end in the SOF panic.

Testing

Tested together with #11598 on main 73a7797:

  • Builds: ptl, ptl-us, mtl, lnl, tgl, tgl-h, wcl, nvl, imx8, imx8m, imx8ulp, native_sim and qemu_xtensa.
  • Host: the host library builds, and the CI testbench steps (SOF alsa-lib/alsa-utils, test topologies, testbench build, host-testbench.sh) pass all 19 component tests.
  • ZTest: 38 of 38 configurations pass, run as in CI.
  • checkpatch: clean.

🤖 Generated with Claude Code

@lgirdwood
lgirdwood force-pushed the topic/zn-rtos-assert-shared branch 2 times, most recently from b1333f3 to 8edd6d5 Compare December 4, 2026 13:08
@lgirdwood

Copy link
Copy Markdown
Member Author

Intention is that user modules should use posix style assert macros, but kernel modules or code should use native zephyr. Pls check and rework the PR.

lrgirdwo and others added 2 commits December 5, 2026 12:00
On Zephyr, rtos/panic.h includes <zephyr/kernel.h>, so code that
includes it for assert() also gets __ASSERT() and __ASSERT_NO_MSG().
Include the <zephyr/sys/__assert.h> 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 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
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 <noreply@anthropic.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
@lgirdwood
lgirdwood force-pushed the topic/zn-rtos-assert-shared branch from 8edd6d5 to 4d4fc69 Compare December 5, 2026 12:09
@lgirdwood lgirdwood changed the title treewide: use __ASSERT_NO_MSG() instead of assert() in shared code kernel: use __ASSERT_NO_MSG() instead of assert() Dec 5, 2026
@lgirdwood

Copy link
Copy Markdown
Member Author

Reworked in 4d4fc69: only the kernel code is converted now (9 sites in the IPC handlers, the IPC3 DAI code, the IPC4 notifications and the dummy DMA driver), and the user code keeps the POSIX assert(). The host rtos/panic.h still provides the Zephyr macros, as these kernel files are also built for the host. #11598 no longer carries any of these changes: it applies to main on its own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants