hujun260 opened a new pull request, #18220:
URL: https://github.com/apache/nuttx/pull/18220

   ## Summary
   Consolidate multiple return statements in the `sysinfo()` function into a 
single
   exit point by inverting the parameter validation condition and restructuring
   the success path to reduce cyclomatic complexity and comply with MISRA HIS 
coding standards.
   
   ## Motivation and Problem
   The original implementation had multiple early return statements for error 
cases
   and success paths, which violates MISRA HIS metric rules for safety-critical 
code.
   This increases cyclomatic complexity and makes code verification and testing 
more
   difficult. Consolidating returns to a single exit point improves 
maintainability
   and compliance with automotive safety standards.
   
   ## Changes
   - Introduce a result variable (`ret`) initialized to `OK` (0)
   - Invert parameter validation condition (info == NULL becomes info != NULL)
   - Move all successful sysinfo operations into the valid parameter branch
   - Move error handling (set_errno and ret = -1) into the else branch
   - Perform single return at function end with the result variable
   - Maintain identical functional behavior with improved code structure
   
   ## Impact
   - **Code Quality**: Reduced cyclomatic complexity through single exit point
   - **Compliance**: Achieves MISRA HIS compliance for return statement metrics
   - **Verifiability**: Single exit point improves static analysis and code 
verification
   - **Maintainability**: Clearer control flow with proper error handling branch
   - **Backward Compatibility**: No functional changes; identical runtime 
behavior
   - **Performance**: No performance impact; compiler optimizations identical
   
   ## Verification
   - [x] Code compiles without warnings on ARM GCC 10.x
   - [x] Verified on QEMU ARMv7-A simulator with multimedia profile
   - [x] System information retrieval verified
   - [x] CPU load calculation verified
   - [x] Memory information aggregation verified (kernel heap, user heap, page 
alloc)
   - [x] Uptime and processor count retrieval verified
   - [x] Error cases (NULL info pointer) verified
   - [x] Static analysis shows improved complexity metrics
   
   ## Testing
   Tested with:
   - ARM GCC 10.x compiler
   - QEMU ARMv7-A simulation
   - System information operations:
     - Valid sysinfo structure initialization
     - CPU load information collection
     - Kernel memory (kumm) and heap memory retrieval
     - Page allocator information retrieval
     - Uptime calculation and processor count
     - NULL pointer parameter error handling
   
   ## Related Issues
   Addresses Coverity static analysis HIS_metric_violation findings.
   
   ## Files Changed
   - `sched/sched/sched_sysinfo.c` (67 lines: 35 insertions, 32 deletions)


-- 
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]

Reply via email to