[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <04864DC4-FA5B-4D7A-8EE5-BDA1E8F88007@collabora.com>
Date: Tue, 14 Jan 2025 15:34:56 -0300
From: Daniel Almeida <daniel.almeida@...labora.com>
To: Alice Ryhl <aliceryhl@...gle.com>
Cc: Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>,
Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...nel.org>,
Trevor Gross <tmgross@...ch.edu>,
linux-kernel@...r.kernel.org,
rust-for-linux@...r.kernel.org
Subject: Re: [PATCH] rust: irq: add support for request_irq()
Hi Alice,
> On 13 Jan 2025, at 11:42, Alice Ryhl <aliceryhl@...gle.com> wrote:
>
> On Thu, Oct 24, 2024 at 4:20 PM Daniel Almeida
> <daniel.almeida@...labora.com> 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
How? T is passed by value, so if request_irq() fails and thus Registration::register() returns Err,
I assume T is dropped.
Or is the pin_init! stuff somehow special here?
— Daniel
Powered by blists - more mailing lists