rongbc opened a new pull request, #20355:
URL: https://github.com/apache/nuttx/pull/20355
## Summary
#7473 established the convention "Don't check the return value of nxsem_init
or
nxmutex_init", but such checks have since accumulated again in the tree.
`nxsem_init()`, `nxsem_destroy()`, `nxmutex_init()`, `nxmutex_destroy()`,
`nxrmutex_init()` and `nxrmutex_destroy()` cannot fail — they always return
`OK` — so those checks and the error paths behind them are dead code that the
compiler cannot always remove: the `-Os` `stm32f103-minimum:nsh` image still
keeps three of them (`nxmutex_init()`, plus the inlined `nxrmutex_destroy()`
in
`group_leave()` and `mm_map_destroy()`).
This PR removes those checks and corrects the return-value documentation of
the
affected interfaces:
- remove the two checks inside the implementations — `if (ret >= 0)` in
`include/nuttx/mutex.h` and `if (ret < 0)` in `libs/libc/misc/lib_mutex.c`
—
and replace the stale "a negated errno value is returned on failure"
comment of
the six functions with "Zero (OK) is always returned." (5 files);
- remove the 54 call sites that test these return values (52 assignment +
check,
2 conditional). Where `err`/`ret` is reused by a later call that can fail,
the
remaining error handling is kept.
No signature, prototype, syscall table entry or POSIX wrapper is touched:
all six
functions still return `int` and still forward their value.
Three commits: remove the checks (38 files) — correct the return-value
comments
(5 files) — nxstyle formatting of the touched files (25 files, droppable).
## Impact
None on API/ABI and none on runtime behavior: the removed branches are never
taken with the current implementations. `-Os` `stm32f103-minimum:nsh`:
`.text`
51,947 B → 51,939 B, dead return-value checks 3 → 0. Same convention as
merged
#7473.
## Testing
Host Linux x86_64; `arm-none-eabi-gcc 10.3-2021.10` and host gcc; flat
builds.
- **Build, `stm32f103-minimum:nsh` (`-Os`)**: full rebuild, 0 warnings
(`-Wall -Wshadow -Wundef`); `.text` 51,947 B → 51,939 B.
- **Real hardware**: flashed to `stm32f103-minimum` (STM32F103C8) — boots to
the
`nsh>` command terminal, no crash, assertion or stack dump.
- **Disassembly**: the three checks above are gone from the `-Os` image, e.g.
`nxmutex_init()` goes from `subs r4, r0, #0` + `blt.n` to `mov r4, r0`.
- **`-O0` `sim:nsh`**, where a leftover check would still be an explicit
branch:
all 30 emitted copies of the four functions contain **zero** branch
instructions, and `sem_init()`/`sem_destroy()` return `OK` with no test
after
`nxsem_init()`/`nxsem_destroy()`.
- **OSTest on `sim`** (as the template asks for core OS changes): 1014 lines,
`ostest_main: Exiting with status 0`, no `FAILED` line and no non-zero
`nerrors`; it covers the touched pthread
mutex/cond/barrier/rwlock/robust/cancel
and semaphore paths.
- **Residual grep**: 11 hits, all intentional — the 9 value-forwarding sites
(`return`, `ret = -fn(...)`) plus the 2 implementation-local `ret =`
forwards
kept for the unchanged `int` contract.
The 17 `arch/` files and 12 driver files in commit 1 are outside these two
configurations (no xtensa/risc-v toolchain on the test host); those edits are
mechanical and get their first compile in CI.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]