hujun260 opened a new pull request, #18217:
URL: https://github.com/apache/nuttx/pull/18217
## Summary
Consolidate multiple return statements in the `profil()` function into a
single
exit point by inverting parameter validation logic and restructuring error
handling
to reduce cyclomatic complexity and comply with MISRA HIS coding standards.
## Motivation and Problem
The original implementation had multiple early return statements for
different
error conditions and success 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 improves maintainability and compliance with automotive safety
standards.
## Changes
- Introduce a result variable (`ret`) initialized to `OK`
- Invert the scale validation condition (scale > 65536 becomes scale <=
65536)
- Restructure parameter validation into nested if-else blocks
- Move successful profiling setup logic into the valid parameter branch
- Move timer cancellation into the parameter error handling branch
- Replace all early returns with single return at function end
- 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 structure instead of multiple
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] Profiling parameter validation verified
- [x] Valid profiling setup path verified
- [x] Invalid scale parameter handling verified
- [x] NULL buffer/zero scale timer cancellation verified
- [x] Watchdog timer start/cancel behavior verified
- [x] Spinlock protection verified
- [x] Static analysis shows improved complexity metrics
## Testing
Tested with:
- ARM GCC 10.x compiler
- QEMU ARMv7-A simulation
- Profiling scenarios:
- Valid scale and buffer parameters (profiling enabled)
- Invalid scale (> 65536) error handling
- NULL buffer parameter (timer cancelled)
- Zero scale parameter (timer cancelled)
- Profiling timer start and cancellation
- Buffer setup with proper offset and highpc calculation
## Files Changed
- `sched/sched/sched_profil.c` (45 lines: 25 insertions, 20 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]