mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Nick Dowsett" <nick42d@gmail.com>
To: "Miguel Ojeda" <miguel.ojeda.sandonis@gmail.com>, <nick42d@gmail.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>,
	"Jean Delvare" <jdelvare@suse.com>,
	linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH] rust: dmi: add basic DMI matching abstraction
Date: Mon, 23 Nov 2026 08:31:11 +0800	[thread overview]
Message-ID: <DN260E1QVCJA.2PKN1JODEAOB0@gmail.com> (raw)
In-Reply-To: <CANiq72mFCq01A_=B0gyaut1rPWeECOdDwP6pD3FBv7n4oH6TWg@mail.gmail.com>

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@kernel.org> 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

  reply	other threads:[~2026-11-23  0:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22  4:28 Nick Dowsett via B4 Relay
2026-11-22 10:37 ` Miguel Ojeda
2026-11-23  0:31   ` Nick Dowsett [this message]
2026-11-23  1:10     ` Miguel Ojeda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DN260E1QVCJA.2PKN1JODEAOB0@gmail.com \
    --to=nick42d@gmail.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=gary@garyguo.net \
    --cc=jdelvare@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=miguel.ojeda.sandonis@gmail.com \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=work@onurozkan.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®