Re: [PATCH] rust: irq: add support for request_irq()
From: Alice Ryhl
Date: Mon Jan 13 2025 - 09:46:58 EST
On Thu, Oct 24, 2024 at 4:20 PM Daniel Almeida
<daniel.almeida@xxxxxxxxxxxxx> wrote:
>
> +impl<T: Handler> Registration<T> {
> + /// Registers the IRQ handler with the system for the given IRQ number. The
> + /// handler must be able to be called as soon as this function returns.
> + pub fn register(
> + irq: u32,
> + flags: Flags,
> + name: &'static CStr,
> + handler: T,
> + ) -> impl PinInit<Self, Error> {
> + try_pin_init!(Self {
> + irq,
> + handler: Opaque::new(handler)
> + })
> + .pin_chain(move |slot| {
> + // SAFETY:
> + // - `handler` points to a valid function defined below.
> + // - only valid flags can be constructed using the `flags` module.
> + // - `devname` is a nul-terminated string with a 'static lifetime.
> + // - `ptr` is a cookie used to identify the handler. The same cookie is
> + // passed back when the system calls the handler.
> + to_result(unsafe {
> + bindings::request_irq(
> + irq,
> + Some(handle_irq_callback::<T>),
> + flags.0,
> + name.as_char_ptr(),
> + &*slot as *const _ as *mut core::ffi::c_void,
> + )
> + })?;
> +
> + Ok(())
> + })
I think this does not run the destructor of `handler` when
`request_irq` returns an error.
Alice