[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DC78ENI8QVIO.1AU7LK858YKTM@kernel.org>
Date: Wed, 20 Aug 2025 13:51:28 +0200
From: "Danilo Krummrich" <dakr@...nel.org>
To: "John Hubbard" <jhubbard@...dia.com>
Cc: "Alexandre Courbot" <acourbot@...dia.com>, "Joel Fernandes"
<joelagnelf@...dia.com>, "Timur Tabi" <ttabi@...dia.com>, "Alistair Popple"
<apopple@...dia.com>, "David Airlie" <airlied@...il.com>, "Simona Vetter"
<simona@...ll.ch>, "Bjorn Helgaas" <bhelgaas@...gle.com>,
Krzysztof Wilczyński <kwilczynski@...nel.org>, "Miguel
Ojeda" <ojeda@...nel.org>, "Alex Gaynor" <alex.gaynor@...il.com>, "Boqun
Feng" <boqun.feng@...il.com>, "Gary Guo" <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>, "Benno Lossin"
<lossin@...nel.org>, "Andreas Hindborg" <a.hindborg@...nel.org>, "Alice
Ryhl" <aliceryhl@...gle.com>, "Trevor Gross" <tmgross@...ch.edu>,
<nouveau@...ts.freedesktop.org>, <linux-pci@...r.kernel.org>,
<rust-for-linux@...r.kernel.org>, "LKML" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v4 1/3] rust: pci: provide access to PCI Class and
Class-related items
On Wed Aug 20, 2025 at 5:08 AM CEST, John Hubbard wrote:
> Allow callers to write Class::STORAGE_SCSI instead of
> bindings::PCI_CLASS_STORAGE_SCSI, for example.
>
> New APIs:
> Class::STORAGE_SCSI, Class::NETWORK_ETHERNET, etc.
> Class::as_raw()
> Class: TryFrom<u32> for Class
> ClassMask: Full, ClassSubclass
> DeviceId::from_class_and_vendor()
> Device::pci_class()
>
> Cc: Danilo Krummrich <dakr@...nel.org>
> Cc: Alexandre Courbot <acourbot@...dia.com>
> Signed-off-by: John Hubbard <jhubbard@...dia.com>
> + /// Returns the PCI class as a `Class` struct.
> + /// Returns an error if the class code is not recognized.
> + pub fn pci_class(&self) -> Result<Class> {
> + // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`.
> + Class::new(unsafe { (*self.as_raw()).class })
> + }
I think all this turned out very nice!
One thing to reconsider would be whether we really want this to be fallible.
It's probably better to define a pci::Class::UNKNOWN and implement
impl From<u32> for Class {
fn from(value: u32) -> Self {
match value {
$(x if x == Self::$variant.0 => Self::$variant,)+
_ => Self::UNKNOWN,
}
}
}
instead.
Powered by blists - more mailing lists