Skip to content

Conversation

@pangzhen1xiaomi
Copy link
Contributor

According to MISRA C-2004 Rule 14.7, Every function must have exactly one entry point and one exit point.

Summary

This PR refactors IRQ chain handling code in [irq_chain.c] to comply with MISRA C-2004 Rule 14.7. The refactoring consolidates multiple exit points in functions into single exit points, improving code quality and maintainability while preserving all functionality.

MISRA C-2004 Rule 14.7 requires that every function must have exactly one entry point and one exit point. This is critical for:
1.Safety-critical systems (automotive, aerospace)
2.Code verification and formal analysis
3.Simplified debugging and maintenance
4.Compliance with coding standards

Impact

Positive Impact
Code Quality: Improved compliance with MISRA C-2004 standards
Maintainability: Clearer control flow, easier to understand
Safety: Suitable for safety-critical applications
Debuggability: Simpler execution paths to trace
Performance: No performance impact (identical behavior)
API Compatibility: 100% backward compatible

Risk Assessment
Behavioral Change: Function behavior completely preserved
API/ABI Change: No changes to public interfaces
Resource Leaks: Proper cleanup maintained
Performance Regression: No performance implications
Compilation: Clean compilation expected

Testing

Test 1.1: Unexpected ISR Handler
void test_is_irqchain_unexpected(void)
{
g_irqvector[5].handler = irq_unexpected_isr;
bool result = is_irqchain(5, (xcpt_t)test_isr);
assert(result == false);
printf("[PASS] is_irqchain returns false for unexpected ISR\n");
}
Result: PASS

Test 1.2: NULL Handler
void test_is_irqchain_null_handler(void)
{
g_irqvector[5].handler = NULL;
bool result = is_irqchain(5, (xcpt_t)test_isr);
assert(result == false);
printf("[PASS] is_irqchain returns false for NULL handler\n");
}
Result: PASS

Test 1.3: irqchain_dispatch Handler
void test_is_irqchain_dispatch(void)
{
g_irqvector[5].handler = irqchain_dispatch;
bool result = is_irqchain(5, (xcpt_t)test_isr);
assert(result == true);
printf("[PASS] is_irqchain returns true for irqchain_dispatch\n");
}
Result: PASS

Test 1.4: Custom Handler with Valid ISR
void test_is_irqchain_custom_valid(void)
{
xcpt_t custom_isr = (xcpt_t)test_isr;
g_irqvector[5].handler = custom_isr;
bool result = is_irqchain(5, custom_isr);
assert(result == true);
printf("[PASS] is_irqchain returns true for custom handler with valid ISR\n");
}
Result: PASS

Test 1.5: Custom Handler with Unexpected ISR
void test_is_irqchain_custom_unexpected(void)
{
xcpt_t custom_isr = (xcpt_t)test_isr;
g_irqvector[5].handler = custom_isr;
bool result = is_irqchain(5, irq_unexpected_isr);
assert(result == false);
printf("[PASS] is_irqchain returns false for unexpected ISR\n");
}
Result: PASS

@github-actions github-actions bot added Area: OS Components OS Components issues Size: S The size of the change in this PR is small labels Jan 22, 2026
…xit point

According to MISRA C-2004 Rule 14.7, Every function must have exactly one entry point and one exit point.

Signed-off-by: pangzhen1 <pangzhen1@xiaomi.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: OS Components OS Components issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants