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

   ## Summary
   Consolidate multiple return statements in the `nxsched_get_param()` function
   into a single exit point and restructure error handling paths to reduce 
cyclomatic
   complexity and comply with MISRA HIS coding standards for safety-critical 
systems.
   
   ## Motivation and Problem
   The original implementation had multiple early return statements for error 
cases,
   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 and restructuring the control 
flow
   improves maintainability and compliance with automotive safety standards.
   
   ## Changes
   - Introduce a result variable (`ret`) initialized to `OK`
   - Replace early error returns with assignment to `ret` variable
   - Restructure parameter validation to use if-else blocks instead of early 
returns
   - Consolidate task lookup and parameter retrieval logic within else blocks
   - 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 nested conditions instead 
of early returns
   - **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] Parameter retrieval for current task verified
   - [x] Parameter retrieval for other tasks verified
   - [x] Sporadic scheduling parameter handling verified
   - [x] Error cases (invalid PID, NULL param) verified
   - [x] Critical section protection verified
   - [x] Static analysis shows improved complexity metrics
   
   ## Testing
   Tested with:
   - ARM GCC 10.x compiler
   - QEMU ARMv7-A simulation
   - Scheduling parameter operations:
     - Get parameters for current task (pid == 0)
     - Get parameters for running task (pid == rtcb->pid)
     - Get parameters for other tasks
     - Invalid PID error handling
     - NULL parameter pointer error handling
     - SCHED_SPORADIC parameter retrieval
     - Non-sporadic priority parameter handling
   
   ## Files Changed
   - `sched/sched/sched_getparam.c` (95 lines: 48 insertions, 47 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