mirror of
https://github.com/apache/nuttx.git
synced 2026-05-14 02:58:01 +08:00
7b154402fb
Previously, IRQ bounds checking (irq >= 0 && irq < NR_IRQS) was duplicated across multiple IRQ subsystem functions before calling IRQ_TO_NDX(). This led to code duplication and inconsistency. This patch consolidates all IRQ bounds checking into the IRQ_TO_NDX() macro itself, which now returns -EINVAL for out-of-bounds IRQ numbers. This approach: 1. Eliminates duplicated bounds checking code 2. Ensures consistent error handling across all IRQ functions 3. Simplifies caller code - just check if IRQ_TO_NDX() returns negative 4. Makes the macro behavior more predictable and self-contained Changes: - Modified IRQ_TO_NDX() to check (irq < 0 || irq >= NR_IRQS) and return -EINVAL - Removed redundant IRQ range checks in irq_attach(), irq_attach_thread(), irq_attach_wqueue(), and irqchain_detach() - Simplified error handling to check ndx < 0 after IRQ_TO_NDX() call This consolidation reduces code size and improves maintainability while preserving all existing error checking functionality. Signed-off-by: pangzhen1 <pangzhen1@xiaomi.com>