Skip to content

ring_buffer: ring_buf_init may trigger assertion depending on Kconfig #98523

@ycsin

Description

@ycsin

Describe the bug

I was upgrading an application from v3.7.0 to v4.2.1. The application compiles fine, but when the kernel initiailzes the shell_uart backend, it triggers an assertion.

static inline void ring_buf_init(struct ring_buf *buf,
uint32_t size,
uint8_t *data)
{
__ASSERT(size <= RING_BUFFER_MAX_SIZE, RING_BUFFER_SIZE_ASSERT_MSG);
buf->size = size;
buf->buffer = data;
ring_buf_internal_reset(buf, 0);
}

This is kinda like a regression, where the same Kconfigs that used to worked in Zephyr v3.7.0 but triggers a runtime fatal error in v4.2.0

Regression

  • This is a regression.

Steps to reproduce

  1. Configures SHELL_BACKEND_SERIAL_TX_RING_BUFFER_SIZE=65536
  2. Compiles the application in v3.7.0 and run - works fine
  3. Compiles the same application in v4.2.0 and run - triggers assert on init

Relevant log output

ASSERTION FAIL [size <= (0xffff / 2)] @ ZEPHYR_BASE/include/zephyr/sys/ring_buffer.h:177	Size too big [0101_000000.044] <err> os: [0101_000000.044] <err> os: mcause: 11, Environment call from M-mode [0101_000000.044] <err> os: mtval: 0 [0101_000000.044] <err> os: a0: 0000000010040dc8 t0: 0000000000000000 [0101_000000.044] <err> os: a1: 0000000000000318 t1: 0000000010048060 [0101_000000.044] <err> os: a2: 0000000000000000 t2: 000000000000003a [0101_000000.044] <err> os: a3: 0000000000000000 t3: 0000000000000318 [0101_000000.044] <err> os: a4: 0000000000000000 t4: 00000000000003b8 [0101_000000.044] <err> os: a5: 0000000000000000 t5: 0000000000000001 [0101_000000.044] <err> os: a6: 0000000010100568 t6: 0000000000000004 [0101_000000.044] <err> os: a7: 00000000100629ee [0101_000000.044] <err> os: sp: 00000000101005a0 [0101_000000.044] <err> os: ra: 0000000010033d10 [0101_000000.044] <err> os: mepc: 000000001002fcf0 [0101_000000.044] <err> os: mstatus: 0000000a00001880 [0101_000000.044] <err> os: [0101_000000.044] <err> os: s0: 0000000010048060 s6: 0000000010040dc8 [0101_000000.044] <err> os: s1: 000000000000003a s7: 0000000000000318 [0101_000000.044] <err> os: s2: 0000000000000318 s8: 0000000000000000 [0101_000000.044] <err> os: s3: 00000000000003b8 s9: 0000000000000000 [0101_000000.044] <err> os: s4: 0000000000000001 s10: 0000000000000000 [0101_000000.044] <err> os: s5: 0000000000000004 s11: 0000000000000000 [0101_000000.044] <err> os: [0101_000000.044] <err> os: call trace: [0101_000000.044] <err> os: 0: sp: 00000000101005a0 ra: 000000001002fcf0 [assert_post_action+0x8] [0101_000000.044] <err> os: 1: sp: 00000000101005b0 ra: 00000000100353a6 [shell_init+0x158] [0101_000000.044] <err> os: 2: sp: 0000000010100610 ra: 0000000010033d40 [enable_shell_uart+0x30] [0101_000000.044] <err> os: 3: sp: 0000000010100620 ra: 000000001003c21a [z_sys_init_run_level+0x4e] [0101_000000.044] <err> os: 4: sp: 0000000010100640 ra: 000000001003c236 [bg_thread_main+0x1a] [0101_000000.044] <err> os: 5: sp: 0000000010100670 ra: 000000001002f402 [z_thread_entry+0xe] [0101_000000.044] <err> os: [0101_000000.044] <err> os: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0 [0101_000000.044] <err> os: Current thread: 0x100f47a8 (main) [0101_000000.044] <err> os: mcause: 11, Environment call from M-mode [0101_000000.044] <err> os: mdcause: 0, unknown [0101_000000.044] <err> os: mtval: 0 [0101_000000.044] <err> os: [0101_000000.044] <err> os: Halting system

Impact

Annoyance – Minor irritation; no significant impact on usability or functionality.

Environment

  • Custom toolchain
  • Zephyr v4.2.1 tagged release

Additional Context

The fix is simple as the assert message was obvious enough to lead user to the source code and realize that they have to enable CONFIG_RING_BUFFER_LARGE, but the upgrade should ideally be seamless especially for in-tree kernel modules such as the shell uart.

See also #85344

Metadata

Metadata

Assignees

Labels

RegressionSomething, which was working, does not anymorearea: Base OSBase OS Library (lib/os)bugThe issue is a bug, or the PR is fixing a bugpriority: mediumMedium impact/importance bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions