[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <2c551130-4f2a-45ec-8191-1b14d14ddd77@nvidia.com>
Date: Mon, 25 Aug 2025 19:22:56 -0700
From: John Hubbard <jhubbard@...dia.com>
To: Alexandre Courbot <acourbot@...dia.com>,
Danilo Krummrich <dakr@...nel.org>
Cc: 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>,
Elle Rhumsaa <elle@...thered-steel.dev>
Subject: Re: [PATCH v6 1/5] rust: pci: provide access to PCI Class and
Class-related items
On 8/25/25 5:17 AM, Alexandre Courbot wrote:
>> + /// Convert a raw 24-bit class code value to a `Class`.
>> + impl From<u32> for Class {
>> + fn from(value: u32) -> Self {
>> + match value {
>> + $(x if x == Self::$variant.0 => Self::$variant,)+
>> + _ => Self::UNKNOWN,
>> + }
>> + }
>
> Should we normalize `value` to 24 bits (i.e. call `to_24bit_class`)
> before doing the match? The constants we compare against are all
> normalized, but if we pass a 16-bit class to this method the result will
> be `UNKNOWN`, unless I missed something.
>
> Being able to store a class as either a 16-bit or 24-bit representation
> in the same type also opens the door to bugs, which we can avoid if we
> always normalize to 24-bit and make the class/subclass representation
> accessible through a convenience method only.
It's constrained by the PCI ID patterns, and should only be used in
order to get values from the C bindings, actually.
>
>> + }
>> + };
>> +}
>> +
>> +/// Once constructed, a `Class` contains a valid PCI Class code.
>> +impl Class {
>> + /// Create a new Class from a raw 24-bit class code.
>> + pub fn new(class_code: u32) -> Self {
>> + Self::from(class_code)
>> + }
>
> Do we need a `new` method when the `From` implementation does exactly
> the same thing and has the same signature?
>
Looks like I'll remove the From, and only provide new, based on the other
thread.
thanks,
--
John Hubbard
Powered by blists - more mailing lists