hujun260 opened a new pull request, #17958:
URL: https://github.com/apache/nuttx/pull/17958
## Summary
Add null-check protection for ISR handler invocation in threaded interrupt
mode. When `isr` is NULL, the system now safely handles the irq_default_handler
without attempting to call a null function pointer. This improves robustness of
the interrupt handling subsystem and aligns with the documented behavior that
NULL ISR triggers isrthread execution.
## Changes
- **sched/irq/irq_attach_thread.c**:
- Replace `DEBUGASSERT(info->handler != NULL)` with safe null-check
conditional
- Only invoke handler if non-NULL, preventing potential null pointer
dereference
- Update comment documentation to clarify behavior when isr is NULL
- **sched/irq/irq_attach_wqueue.c**:
- Add null-check guard for info->handler before invocation
- Initialize `ret` variable to `IRQ_WAKE_THREAD` for correct default
behavior
- Fix handler call parameter from generic `arg` to `info->arg` for
consistency
- Update comment to accurately reflect NULL isr behavior
## Benefits & Technical Details
- **Safety**: Eliminates null pointer dereference risk when NULL ISR is
passed during handler attachment/detachment
- **Documentation alignment**: Comment now accurately reflects
implementation - NULL isr triggers isrthread callback
- **Consistency**: Both irq_attach_thread and irq_attach_wqueue use
identical null-check pattern
- **Correct parameter passing**: Fixed parameter type in irq_attach_wqueue
to pass correct context data
## Testing
- Verified irq_default_handler correctly handles NULL handler pointers
without crashing
- Confirmed isrthread is properly invoked when isr is NULL during IRQ
attachment
- Tested IRQ attachment and detachment with both NULL and non-NULL ISR
handlers
- Validated on systems with threaded and work queue based interrupt handlers
## Impact
- **Robustness**: Safer interrupt handler attachment/detachment sequence
- **Compatibility**: No API changes, fully backward compatible
- **Documentation**: Corrected and clarified ISR NULL handling behavior
- **Scope**: Affects threaded interrupt mode
(CONFIG_ARCH_IRQHANDLER_ATTACH_THREAD) and work queue based IRQ handling
--
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]