Skip to content

mm/mempool: MISRA-C single exit and unsigned constants - #22744

Open
CV-Bowen wants to merge 4 commits into
apache:masterfrom
CV-Bowen:up/P234-mempool-misra
Open

CV-Bowen wants to merge 4 commits into
apache:masterfrom
CV-Bowen:up/P234-mempool-misra

Conversation

@CV-Bowen

@CV-Bowen CV-Bowen commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Summary

MISRA-C cleanups in mm/mempool/mempool.c, the first of a series that
brings the mempool MISRA/Coverity fixes in. No functional change intended.

  • mm/mempool: Complies with MISRA-C single-input single-output rule. (x3):
    mempool_deinit(), mempool_init() and mempool_allocate() now have a
    single return at the end; the early returns become ret /
    if (ret >= 0) / a do { } while (retry) loop in place of goto retry.
  • mm/mempool: follow MISRA-C 2012 11.4: unsigned constants (0u) in
    comparisons with unsigned values, and an explicit cast for
    info->nwaiter, in mempool.c, mempool.h, malloc.h, mm_malloc.c,
    mm_memdump.c and fs_procfsproc.c.

The code is current master's: mempool_can_wait(), the backtrace hooks
and the expandable-pool count in mempool_navail() are kept as they are,
only the control flow and literals change.

Impact

  • No API, ABI or Kconfig change.
  • Same behaviour on every path, including the -EBUSY / -ENOMEM returns
    and the wait/retry in mempool_allocate().

Testing

Host: Ubuntu 22.04.5 LTS x86_64, QEMU version 10.2.1, sim: cc (Ubuntu
13.1.0-8ubuntu1~22.04) 13.1.0, qemu-armv8a: aarch64-none-elf-gcc (Arm GNU
Toolchain 12.2.Rel1) 12.2.1

mempool cases: sim:nsh plus

CONFIG_ALLOW_MIT_COMPONENTS=y
CONFIG_LIBC_REGEX=y
CONFIG_TESTING_CMOCKA=y
CONFIG_TESTING_CMOCKA_PROG=y
CONFIG_TESTS_TESTSUITES=y
CONFIG_CM_MM_TEST=y
CONFIG_MM_HEAP_MEMPOOL_THRESHOLD=256
CONFIG_FS_PROCFS=y

nsh> cmocka --suite cmocka_mm_test --skip test_nuttx_mm11

test_nuttx_mm10 (init / allocate / navail / release / deinit, including
-EBUSY) and test_nuttx_mm12 (info / info_task / memdump) run the
changed functions.

cmocka_mm_test
[       OK ] test_nuttx_mm01
[       OK ] test_nuttx_mm02
[       OK ] test_nuttx_mm03
[       OK ] test_nuttx_mm04
[       OK ] test_nuttx_mm05
[       OK ] test_nuttx_mm06
[       OK ] test_nuttx_mm07
[       OK ] test_nuttx_mm08
[       OK ] test_nuttx_mm09
[       OK ] test_nuttx_mm10
[  SKIPPED ] test_nuttx_mm11
[       OK ] test_nuttx_mm12
[  PASSED  ] 11 test(s).

test_nuttx_mm11 (mempool_multiple) is skipped because it asserts the
same way on current master without this PR:

Assertion failed mpool->dict_row_num > row: at file: /mm/mempool/mempool_multiple.c:262

This PR does not touch mempool_multiple.c.

Regression: sim:rpserver/rpproxy and qemu-armv8a:rpserver/rpproxy boot
and pass the rpmsg cases (dump, ping, rpmsgfs; 15/15). qemu-armv8a was
built with LIBC_ENVPATH and BINFMT_CHECKEXEC disabled, which current
master needs for nxinit to start nsh there; unrelated to this change.

checkpatch passes on all commits.

MISRA-C 2012 Rule 15.5 asks for a single point of exit. Make
mempool_deinit() return once at the end, carrying -EBUSY in ret.

Signed-off-by: wangzhi16 <wangzhi16@xiaomi.com>
Use unsigned constants when comparing unsigned values and cast the
negated semaphore count explicitly when storing it in nwaiter.

Signed-off-by: wangzhi16 <wangzhi16@xiaomi.com>
MISRA-C 2012 Rule 15.5 asks for a single point of exit. Make
mempool_init() return once at the end, carrying -ENOMEM in ret.

Signed-off-by: wangzhi16 <wangzhi16@xiaomi.com>
MISRA-C 2012 Rule 15.5 asks for a single point of exit. Make
mempool_allocate() return once at the end and replace the goto retry
with a do-while loop.

Signed-off-by: wangzhi16 <wangzhi16@xiaomi.com>
@CV-Bowen
CV-Bowen force-pushed the up/P234-mempool-misra branch from ad0602d to 1475622 Compare December 2, 2026 16:12
@github-actions github-actions Bot added Area: File System File System issues Size: M The size of the change in this PR is medium labels Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

mps2-an500-citest

  • flash: .text +8 B (+0.0%, 254,508 B / 4,194,304 B, total: 6% used)

qemu-intel64

  • Code: .text -6 B (-0.0%, 8,711,164 B)

s698pm-dkit

  • Code: .text +16 B (+0.0%, 416,704 B)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

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

Labels

Area: File System File System issues Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants