lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <fa1c51af-a517-4a04-a5dc-72e4410063ee@nvidia.com>
Date: Wed, 20 Aug 2025 10:20:16 -0700
From: John Hubbard <jhubbard@...dia.com>
To: Danilo Krummrich <dakr@...nel.org>
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 8/20/25 4:51 AM, Danilo Krummrich wrote:
> 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.

Yes, I went back and forth on whether Class and Vendor should be
fallible, and finally settled on the wrong choice. haha :)


thanks,
-- 
John Hubbard


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ