On Mon, Jul 07, 2025 at 10:30:27PM +0200, Benno Lossin wrote: > On Mon Jul 7, 2025 at 6:18 PM CEST, Daniel Almeida wrote: > > Alice, > > > > […] > > > >>> +/// The value that can be returned from an IrqHandler or a ThreadedIrqHandler. > >>> +pub enum IrqReturn { > >>> + /// The interrupt was not from this device or was not handled. > >>> + None, > >>> + > >>> + /// The interrupt was handled by this device. > >>> + Handled, > >>> +} > >>> + > >>> +impl IrqReturn { > >>> + fn into_inner(self) -> u32 { > >>> + match self { > >>> + IrqReturn::None => bindings::irqreturn_IRQ_NONE, > >>> + IrqReturn::Handled => bindings::irqreturn_IRQ_HANDLED, > >> > >> One option is to specify these in the enum: > >> > >> /// The value that can be returned from an IrqHandler or a ThreadedIrqHandler. > >> pub enum IrqReturn { > >> /// The interrupt was not from this device or was not handled. > >> None = bindings::irqreturn_IRQ_NONE, > >> > >> /// The interrupt was handled by this device. > >> Handled = bindings::irqreturn_IRQ_HANDLED, > >> } > > > > This requires explicitly setting #[repr(u32)], which is something that was > > reverted at an earlier iteration of the series on Benno’s request. > > Yeah I requested this, because it increases the size of the enum to 4 > bytes and I think we should try to make rust enums as small as possible. > > @Alice what's the benefit of doing it directly in the enum? Basically all uses of this enum are going to look like this: fn inner() -> IrqReturn { if !should_handle() { return IrqReturn::None; } // .. handle the irq IrqReturn::Handled } fn outer() -> u32 { match inner() { IrqReturn::None => bindings::irqreturn_IRQ_NONE, IrqReturn::Handled => bindings::irqreturn_IRQ_HANDLED, } } Setting the discriminant to the values ensures that the match in outer() is a no-op. The enum is never going to be stored long-term anywhere so its size doesn't matter. Alice