Skip to content

Conversation

@fxysunshine
Copy link
Contributor

@fxysunshine fxysunshine commented Jan 19, 2026

Summary

This PR addresses a small set of MISRA C:2012 and Coverity findings across NuttX core code.
The changes are focused on type-safety, initialization, and simplifying return paths without altering intended behavior.

Key updates:

  • Fix MISRA Rule 10.4 by using the proper enum type for g_nx_initstate.
  • Fix MISRA Rule 10.3 in ARMv8-R IRQ helpers by using unsigned constants (1u, ~1u) for bit operations.
  • Fix a Coverity uninitialized-field report by zero-initializing posix_spawnattr_t in posix_spawnattr_init().
  • Refactor several scheduler/task helpers to use a single return path (Coverity “RETURN” metric), improving readability and reducing early returns.

Impact

  • Functional impact: No intended functional change; these are compliance/quality fixes (type correctness, initialization, control-flow cleanup).
  • Affected areas:
    • Scheduler/task utilities (sched/task/*)
    • System init state (include/nuttx/init.h, sched/init/nx_start.c)
    • libc spawn attributes (libs/libc/spawn/lib_psa_init.c)
    • ARMv8-R IRQ helpers (arch/arm/include/armv8-r/irq.h)
  • Risk: Low. Changes are localized and primarily mechanical (types, constants, return-path refactors).

Testing

  • Environment:
    • Host: Linux
    • Build system: CMake
    • Configurations:
    • sim:nsh and qemu-armv7a:nsh
  • Steps:
  1. Configure and build sim:nsh (CMake):
    • cmake -B build -DBOARD_CONFIG=sim:nsh -GNinja
    • cmake --build build -j
  2. Configure and build qemu-armv7a:nsh (CMake):
    • cmake -B build -DBOARD_CONFIG=qemu-armv7a:nsh -GNinja
    • cmake --build build -j
  3. Boot and run NSH smoke checks:
    • Run help
    • Run ps ...
  • Results:
    • MISRA/Coverity: PASS (no new issues introduced; targeted findings addressed)
    • sim:nsh (CMake): PASS (build + NSH smoke)
    • qemu-armv7a:nsh (CMake): PASS (build + NSH smoke)

Use a local ret variable and return once at the end.
This keeps the IDLE_PROCESS_ID fallback behavior unchanged.
Addresses Coverity HIS_metric_violation: RETURN.

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
Replace early return with a ret flag to unify the exit path.
Keep critical section behavior unchanged while simplifying control flow.
Addresses Coverity HIS_metric_violation: RETURN.

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
Initialize ret and propagate scheduler/param errors via a single return.
Make spawn_file_is_duplicateable() decision explicit using a dup state.
Addresses Coverity HIS_metric_violation: RETURN.

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
Refactor nxtask_setup_stackargs() to use a single ret exit path.
Avoid partially-initialized state on error paths and improve readability.
Addresses Coverity HIS_metric_violation: RETURN.

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
Use 1u/~1u constants for TPIDRPRW bit operations.
Avoid implicit conversion to a different underlying type (MISRA Rule 10.3).
No functional change to task pointer tagging logic.

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
Zero-initialize posix_spawnattr_t in posix_spawnattr_init().
Prevent use of uninitialized fields reported by Coverity.
Preserve existing default flag initialization.

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
Change g_nx_initstate type from uint8_t to enum nx_initstate_e.
Avoid enum/integer base-type mismatch in init state comparisons.
Satisfies MISRA C:2012 Rule 10.4 without behavior change.

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
@github-actions github-actions bot added Arch: arm Issues related to ARM (32-bit) architecture Area: OS Components OS Components issues Size: M The size of the change in this PR is medium labels Jan 19, 2026
anchao
anchao previously requested changes Jan 19, 2026
@jerpelea jerpelea changed the title MISRA/Coverity cleanups in scheduler, init, libc spawn, and ARMv8-R IRQ helpers sched/task: MISRA/Coverity cleanups in scheduler, init, libc spawn, and ARMv8-R IRQ helpers Jan 20, 2026
@xiaoxiang781216 xiaoxiang781216 merged commit cd95883 into apache:master Jan 21, 2026
40 checks passed
@fxysunshine fxysunshine deleted the misra-fixes-20260119 branch January 21, 2026 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: arm Issues related to ARM (32-bit) architecture Area: OS Components OS Components 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.

5 participants