sem_rw: Consolidate return statements in down_write_trylock() for MISRA HIS compliance #18207
+10
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Consolidate multiple return statements in the
down_write_trylock()functioninto a single exit point to improve code quality and comply with MISRA HIS
coding standards for safety-critical systems.
Motivation and Problem
The original implementation had multiple return points (early return for failure
and return at the end for success), 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
ret) initialized to 1 (success)ret = 0Impact
Verification
Testing
Tested with:
Files Changed
sched/semaphore/sem_rw.c(17 lines: 10 insertions, 7 deletions)