Re: [PATCH v2 1/5] rust: pci: convert IrqVectorRegistration to a lifetime-managed owning type
From: Gary Guo
Date: Wed Aug 12 2026 - 15:05:53 EST
On Wed Aug 12, 2026 at 7:47 PM BST, Danilo Krummrich wrote:
> On Wed Aug 12, 2026 at 8:11 PM CEST, Gary Guo wrote:
>> Well, I'd expect some drivers want to do `.vector(v).expect()` rather than just
>> propagating the error if `v` is a constant that is less than `min_vecs`..
>
> This is nothing we want drivers to do; this API is only ever called from a
> fallible context anyway and propagating costs nothing, but on the other hand, if
> the driver gets it wrong, we'd BUG() the whole kernel for no value.
Well, if you ask for an interrupt and got one, you'd better got one! If the case
is actually "we'd BUG() the kernel", then it probably should because something
is catastrophically wrong. I'd even consider `unwrap_unchecked` to be valid
there and in my view `BUG()` is less damaging then UB.
I don't like the fact that we propagate error code because we can. Propagating
error comes with a cost: it's one extra control flow that developer needs to
consider; more code is generated because the destructors that's currently
available still needs to be executed; and the code will have 0% coverage because
it'd never occur as
/// `dev` has an allocation of `count` interrupt vectors
is the type invariant of `IrqVectorRegistration`.
If you write additional error checks in C people will complain it's adding dead
code. I don't want Rust's strong type system to be penalizing by forcing error
checks to places where trhey don't belong. I am not seeing `expect()` as the
equivalent of `BUG_ON`; it's just the way you deal with a stronger type system.
Best,
Gary