rust-embedded/rust-raspberrypi-OS-tutorials · critical

Attempt to enable IRQ {} for device {}, but driver does not

Error message

Attempt to enable IRQ {} for device {}, but driver does not support this

What it means

This is a default trait-method implementation for the DeviceDriver trait that always panics. It exists so that drivers which have no interrupt support can inherit a stub instead of being forced to implement register_and_enable_irq_handler themselves. Hitting it means you called the IRQ-registration path on a driver that never opted into interrupts.

Source

Thrown at 20_timer_callbacks/kernel/src/driver.rs:45

        /// Called by the kernel to bring up the device.
        ///
        /// # Safety
        ///
        /// - During init, drivers might do stuff with system-wide impact.
        unsafe fn init(&self) -> Result<(), &'static str> {
            Ok(())
        }

        /// Called by the kernel to register and enable the device's IRQ handler.
        ///
        /// Rust's type system will prevent a call to this function unless the calling instance
        /// itself has static lifetime.
        fn register_and_enable_irq_handler(
            &'static self,
            irq_number: &Self::IRQNumberType,
        ) -> Result<(), &'static str> {
            panic!(
                "Attempt to enable IRQ {} for device {}, but driver does not support this",
                irq_number,
                self.compatible()
            )
        }
    }
}

/// Tpye to be used as an optional callback after a driver's init() has run.
pub type DeviceDriverPostInitCallback = unsafe fn() -> Result<(), &'static str>;

/// A descriptor for device drivers.
pub struct DeviceDriverDescriptor<T>
where
    T: 'static,
{
    device_driver: &'static (dyn interface::DeviceDriver<IRQNumberType = T> + Sync),
    post_init_callback: Option<DeviceDriverPostInitCallback>,

View on GitHub (pinned to 644474cc09)

Solutions

  1. Do not set an irq_number on the driver's descriptor, since the driver declares no interrupt support.
  2. Implement register_and_enable_irq_handler for the driver in its DeviceDriver impl if it actually supports interrupts.
  3. Verify the driver instance is the intended concrete type, not a stub/null driver that only carries the default trait implementation.

Example fix

// before
impl DeviceDriver for UartDriver {
    // register_and_enable_irq_handler not implemented -> default panicking stub used
}

// after
impl DeviceDriver for UartDriver {
    fn register_and_enable_irq_handler(
        &'static self,
        irq_number: &Self::IRQNumberType,
    ) -> Result<(), &'static str> {
        // real implementation: route IRQ to the handler
        irq_manager.register_handler(irq_handler_descriptor(irq_number))
    }
}
Defensive patterns

Strategy: validation

Validate before calling

// Rust: check driver declares IRQ support before asking it to register
if driver.compatible().contains("no-irq") {
    return Err("driver does not support IRQ registration");
}
// or check descriptor has no irq_number:
if descriptor.irq_number.is_some() && !driver.supports_irqs() {
    return Err("irq_number set on IRQ-incapable driver");
}

Type guard

fn supports_irqs<D: DeviceDriver>(_d: &D) -> bool { false } // specialize via const flag on the driver type

Prevention

When it happens

Trigger: Calling register_and_enable_irq_handler() on a DeviceDriver that only implements the default trait method (no interrupt capability), or registering an IRQ descriptor whose irq_number points at such a driver during init_drivers_and_irqs.

Common situations: Adding a new device driver without IRQ support but accidentally giving its descriptor an irq_number; refactoring driver traits so a previously interrupt-capable driver lost its custom register_and_enable_irq_handler; wiring a driver into the IRQ manager before implementing its handler.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of rust-embedded/rust-raspberrypi-OS-tutorials@644474cc09 (2026-09-06). Data as JSON: /api/errors/05220f9c816ceea6. Report an issue: GitHub.