Re: [PATCH] rust: dmi: add basic DMI matching abstraction

From: Miguel Ojeda

Date: Sun Nov 22 2026 - 05:37:37 EST


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.

Since I noticed this while going through the list, let me throw some
nits from a quick pass at the code if you don't mind...

> +/// # Invariant

# Invariants

> +#[expect(missing_docs, reason = "C version of these consts are undocumented")]

(It may be a nice time to take the chance to document these in C, but
out-of-scope for the patch, of course.)

> +/// # use kernel::dmi::{self, Field};

Vertical formatting.

> +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.

`ptr` has just been checked to be non-null, therefore ...

Thanks!

Cheers,
Miguel