Re: [PATCH] rust: dmi: add basic DMI matching abstraction
From: Nick Dowsett
Date: Sun Nov 22 2026 - 19:31:36 EST
Hi Miguel,
Thanks very much for taking a look!
On Sun Nov 22, 2026 at 6:37 PM AWST, Miguel Ojeda wrote:
> On Sun, Nov 22, 2026 at 5:28 AM Nick Dowsett via B4 Relay
> <devnull+nick42d.gmail.com@xxxxxxxxxx> wrote:
>>
>> `dmi::get_system_info` is currently marked safe under the assumption that
>> Rust code is always called after DMI is initialised. Would be keen to
>> have this validated. Alternatively I think a minimal patch to C could
>> actually make this safe earlier if required.
>
> Please avoid soundness holes unless there is really no other way out
> and/or it would be very, very onerous to do. The bar is really high
> here, i.e. if this is just an `unsafe` function, then please simply
> mark it as such, which in turns allows us to document why and to force
> others to ensure it is correct when calling it etc.
>
> Of course, if there is a way to make it safe (whether with a change on
> the C side or with API design on the Rust side etc.), then that is
> even better.
Sounds good from my side. I think initially it's OK to mark this unsafe
- the precondition will be easy to satisfy for the callers. Seperately
I can then investigate a C patch (I think using atomics for
dmi_available).
>> +/// # use kernel::dmi::{self, Field};
>
> Vertical formatting.
Just checking here - is this still applicable for doctests? I copied
some of the example from another subsystem. There could be some
conciseness benefits from not doing this here?
>> +pub fn get_system_info(field: Field) -> Option<&'static CStr> {
>> + // NOTE: This can be upgraded to cfg-select post Rust 1.95.
>
> `cfg_select!`
>
> Though I am not convinced we want this sort of comment -- it is true
> that we have similar comments for explicit workarounds we want to
> remove later on, but in a case like this it is the "standard" way of
> writing the code at least at the moment, rather than an actual
> workaround. And we can always grep/LLM for these improvements when we
> bump the minimum version.
>
>> + if ptr.is_null() {
>> + return None;
>> + }
>
> Newline after this?
>
>> + // SAFETY: If non-null, `dmi_get_system_info` returns a C string that
>> + // lives for the life of the kernel.
>
> I would word sentences like this stating what is known to be true and
> why (since that adds information), rather than conditionally (since
> that "repeats" the contract of the callee), e.g.
All ok with me, I shall address in v2 within the next couple of days.
Cheers,
Nick