rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Hubbard <jhubbard@nvidia.com>
To: Alexandre Courbot <acourbot@nvidia.com>,
	Danilo Krummrich <dakr@kernel.org>
Cc: "Joel Fernandes" <joelagnelf@nvidia.com>,
	"Timur Tabi" <ttabi@nvidia.com>,
	"Alistair Popple" <apopple@nvidia.com>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"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>,
	nouveau@lists.freedesktop.org, linux-pci@vger.kernel.org,
	rust-for-linux@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>,
	"Elle Rhumsaa" <elle@weathered-steel.dev>
Subject: Re: [PATCH v6 1/5] rust: pci: provide access to PCI Class and Class-related items
Date: Mon, 25 Aug 2025 19:22:56 -0700	[thread overview]
Message-ID: <2c551130-4f2a-45ec-8191-1b14d14ddd77@nvidia.com> (raw)
In-Reply-To: <DCBI3A82MOFN.3R7O7I6U6D7LN@nvidia.com>

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


  reply	other threads:[~2025-08-26  2:23 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-22  2:03 [PATCH v6 0/5] rust, nova-core: PCI Class, Vendor support John Hubbard
2025-08-22  2:03 ` [PATCH v6 1/5] rust: pci: provide access to PCI Class and Class-related items John Hubbard
2025-08-25 12:17   ` Alexandre Courbot
2025-08-26  2:22     ` John Hubbard [this message]
2025-08-22  2:03 ` [PATCH v6 2/5] rust: pci: provide access to PCI Vendor values John Hubbard
2025-08-25 12:33   ` Alexandre Courbot
2025-08-25 12:47     ` Danilo Krummrich
2025-08-26  2:20       ` John Hubbard
2025-08-26 20:38       ` John Hubbard
2025-08-26 20:45         ` Danilo Krummrich
2025-08-26 20:58           ` John Hubbard
2025-08-26 21:00             ` Danilo Krummrich
2025-08-26 21:12               ` John Hubbard
2025-08-26  2:19     ` John Hubbard
2025-08-22  2:03 ` [PATCH v6 3/5] rust: pci: add DeviceId::from_class_and_vendor() method John Hubbard
2025-08-22  2:03 ` [PATCH v6 4/5] gpu: nova-core: avoid probing non-display/compute PCI functions John Hubbard
2025-08-22  2:03 ` [PATCH v6 5/5] rust: pci: use pci::Vendor instead of bindings::PCI_VENDOR_ID_* John Hubbard

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=2c551130-4f2a-45ec-8191-1b14d14ddd77@nvidia.com \
    --to=jhubbard@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=apopple@nvidia.com \
    --cc=bhelgaas@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=elle@weathered-steel.dev \
    --cc=gary@garyguo.net \
    --cc=joelagnelf@nvidia.com \
    --cc=kwilczynski@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=nouveau@lists.freedesktop.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tmgross@umich.edu \
    --cc=ttabi@nvidia.com \
    /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;
as well as URLs for NNTP newsgroup(s).