rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] rust: pci: display symbolic PCI vendor and class names
@ 2025-09-25  1:33 John Hubbard
  2025-09-25  1:33 ` [PATCH 1/2] rust: pci: display symbolic PCI " John Hubbard
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: John Hubbard @ 2025-09-25  1:33 UTC (permalink / raw)
  To: Danilo Krummrich
  Cc: Alexandre Courbot, Joel Fernandes, Timur Tabi, Alistair Popple,
	David Airlie, Simona Vetter, Bjorn Helgaas,
	Krzysztof Wilczyński, Miguel Ojeda, Alex Gaynor, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, nouveau, linux-pci, rust-for-linux,
	LKML, John Hubbard

Hi,

This applies to:

  https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git

It's a small follow up to these commits in that same branch:

commit 5e20962a9fc8 ("rust: pci: provide access to PCI Vendor values")
commit ed78a01887e2 ("rust: pci: provide access to PCI Class and Class-related items")

Danilo, I've added your Suggested-by to these.

John Hubbard (2):
  rust: pci: display symbolic PCI class names
  rust: pci: display symbolic PCI vendor names

 rust/kernel/pci/id.rs | 36 +++++++++++++++++++++++-------------
 1 file changed, 23 insertions(+), 13 deletions(-)


base-commit: d4a5d397c7fb1ca967e0da202cac196e7324f4ea
-- 
2.51.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/2] rust: pci: display symbolic PCI class names
  2025-09-25  1:33 [PATCH 0/2] rust: pci: display symbolic PCI vendor and class names John Hubbard
@ 2025-09-25  1:33 ` John Hubbard
  2025-09-25  1:33 ` [PATCH 2/2] rust: pci: display symbolic PCI vendor names John Hubbard
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: John Hubbard @ 2025-09-25  1:33 UTC (permalink / raw)
  To: Danilo Krummrich
  Cc: Alexandre Courbot, Joel Fernandes, Timur Tabi, Alistair Popple,
	David Airlie, Simona Vetter, Bjorn Helgaas,
	Krzysztof Wilczyński, Miguel Ojeda, Alex Gaynor, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, nouveau, linux-pci, rust-for-linux,
	LKML, John Hubbard

The Display implementation for Class was forwarding directly to Debug
printing, resulting in raw hex values instead of PCI Class strings.

Improve things by doing a stringify!() call for each PCI Class item.
This now prints symbolic names such as "DISPLAY_VGA", instead of
"Class(0x030000)". It still falls back to Debug formatting for unknown
class values.

Suggested-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
---
 rust/kernel/pci/id.rs | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/rust/kernel/pci/id.rs b/rust/kernel/pci/id.rs
index 8ee1dc5c3057..6e081de30faf 100644
--- a/rust/kernel/pci/id.rs
+++ b/rust/kernel/pci/id.rs
@@ -50,6 +50,17 @@ impl Class {
                 pub const $variant: Self = Self(Self::to_24bit_class($binding));
             )+
         }
+
+        impl fmt::Display for Class {
+            fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+                match self {
+                    $(
+                        &Self::$variant => write!(f, stringify!($variant)),
+                    )+
+                    _ => <Self as fmt::Debug>::fmt(self, f),
+                }
+            }
+        }
     };
 }
 
@@ -87,12 +98,6 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     }
 }
 
-impl fmt::Display for Class {
-    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        <Self as fmt::Debug>::fmt(self, f)
-    }
-}
-
 impl ClassMask {
     /// Get the raw mask value.
     #[inline]
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] rust: pci: display symbolic PCI vendor names
  2025-09-25  1:33 [PATCH 0/2] rust: pci: display symbolic PCI vendor and class names John Hubbard
  2025-09-25  1:33 ` [PATCH 1/2] rust: pci: display symbolic PCI " John Hubbard
@ 2025-09-25  1:33 ` John Hubbard
  2025-09-25  1:38   ` John Hubbard
  2025-09-25  3:01 ` [PATCH 0/2] rust: pci: display symbolic PCI vendor and class names Alexandre Courbot
  2025-09-25 16:04 ` Danilo Krummrich
  3 siblings, 1 reply; 8+ messages in thread
From: John Hubbard @ 2025-09-25  1:33 UTC (permalink / raw)
  To: Danilo Krummrich
  Cc: Alexandre Courbot, Joel Fernandes, Timur Tabi, Alistair Popple,
	David Airlie, Simona Vetter, Bjorn Helgaas,
	Krzysztof Wilczyński, Miguel Ojeda, Alex Gaynor, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, nouveau, linux-pci, rust-for-linux,
	LKML, John Hubbard

The Display implementation for Vendor was forwarding directly to Debug
printing, resulting in raw hex values instead of PCI Vendor strings.

Improve things by doing a stringify!() call for each PCI Vendor item.
This now prints symbolic names such as "NVIDIA", instead of
"Vendor(0x10de)". It still falls back to Debug formatting for unknown
class values.

Suggested-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
---
 rust/kernel/pci/id.rs | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/rust/kernel/pci/id.rs b/rust/kernel/pci/id.rs
index 6e081de30faf..63db4d5f5617 100644
--- a/rust/kernel/pci/id.rs
+++ b/rust/kernel/pci/id.rs
@@ -135,6 +135,18 @@ impl Vendor {
                 pub const $variant: Self = Self($binding as u16);
             )+
         }
+
+        impl fmt::Display for Vendor {
+            #[inline]
+            fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+                match self {
+                    $(
+                        &Self::$variant => write!(f, stringify!($variant)),
+                    )+
+                    _ => <Self as fmt::Debug>::fmt(self, f),
+                }
+            }
+        }
     };
 }
 
@@ -160,13 +172,6 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     }
 }
 
-impl fmt::Display for Vendor {
-    #[inline]
-    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        <Self as fmt::Debug>::fmt(self, f)
-    }
-}
-
 define_all_pci_classes! {
     NOT_DEFINED                = bindings::PCI_CLASS_NOT_DEFINED,                // 0x000000
     NOT_DEFINED_VGA            = bindings::PCI_CLASS_NOT_DEFINED_VGA,            // 0x000100
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] rust: pci: display symbolic PCI vendor names
  2025-09-25  1:33 ` [PATCH 2/2] rust: pci: display symbolic PCI vendor names John Hubbard
@ 2025-09-25  1:38   ` John Hubbard
  0 siblings, 0 replies; 8+ messages in thread
From: John Hubbard @ 2025-09-25  1:38 UTC (permalink / raw)
  To: Danilo Krummrich
  Cc: Alexandre Courbot, Joel Fernandes, Timur Tabi, Alistair Popple,
	David Airlie, Simona Vetter, Bjorn Helgaas,
	Krzysztof Wilczyński, Miguel Ojeda, Alex Gaynor, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, nouveau, linux-pci, rust-for-linux,
	LKML

On 9/24/25 6:33 PM, John Hubbard wrote:
> The Display implementation for Vendor was forwarding directly to Debug
> printing, resulting in raw hex values instead of PCI Vendor strings.
> 
> Improve things by doing a stringify!() call for each PCI Vendor item.
> This now prints symbolic names such as "NVIDIA", instead of
> "Vendor(0x10de)". It still falls back to Debug formatting for unknown
> class values.
> 
> Suggested-by: Danilo Krummrich <dakr@kernel.org>
> Signed-off-by: John Hubbard <jhubbard@nvidia.com>
> ---
>  rust/kernel/pci/id.rs | 19 ++++++++++++-------
>  1 file changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/rust/kernel/pci/id.rs b/rust/kernel/pci/id.rs
> index 6e081de30faf..63db4d5f5617 100644
> --- a/rust/kernel/pci/id.rs
> +++ b/rust/kernel/pci/id.rs
> @@ -135,6 +135,18 @@ impl Vendor {
>                  pub const $variant: Self = Self($binding as u16);
>              )+
>          }
> +
> +        impl fmt::Display for Vendor {
> +            #[inline]

That #[inline] snuck in somehow (it's not in Class), but it should
not be there, because this expands to many lines of implementation.

If there is a v2 I'll remove it, otherwise maybe we can just ask
the maintainer to snip out that line.

thanks,
John Hubbard

> +            fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
> +                match self {
> +                    $(
> +                        &Self::$variant => write!(f, stringify!($variant)),
> +                    )+
> +                    _ => <Self as fmt::Debug>::fmt(self, f),
> +                }
> +            }
> +        }
>      };
>  }
>  
> @@ -160,13 +172,6 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
>      }
>  }
>  
> -impl fmt::Display for Vendor {
> -    #[inline]
> -    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
> -        <Self as fmt::Debug>::fmt(self, f)
> -    }
> -}
> -
>  define_all_pci_classes! {
>      NOT_DEFINED                = bindings::PCI_CLASS_NOT_DEFINED,                // 0x000000
>      NOT_DEFINED_VGA            = bindings::PCI_CLASS_NOT_DEFINED_VGA,            // 0x000100



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/2] rust: pci: display symbolic PCI vendor and class names
  2025-09-25  1:33 [PATCH 0/2] rust: pci: display symbolic PCI vendor and class names John Hubbard
  2025-09-25  1:33 ` [PATCH 1/2] rust: pci: display symbolic PCI " John Hubbard
  2025-09-25  1:33 ` [PATCH 2/2] rust: pci: display symbolic PCI vendor names John Hubbard
@ 2025-09-25  3:01 ` Alexandre Courbot
  2025-09-25 23:27   ` John Hubbard
  2025-09-25 16:04 ` Danilo Krummrich
  3 siblings, 1 reply; 8+ messages in thread
From: Alexandre Courbot @ 2025-09-25  3:01 UTC (permalink / raw)
  To: John Hubbard, Danilo Krummrich
  Cc: Alexandre Courbot, Joel Fernandes, Timur Tabi, Alistair Popple,
	David Airlie, Simona Vetter, Bjorn Helgaas,
	Krzysztof Wilczyński, Miguel Ojeda, Alex Gaynor, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, nouveau, linux-pci, rust-for-linux,
	LKML

On Thu Sep 25, 2025 at 10:33 AM JST, John Hubbard wrote:
> Hi,
>
> This applies to:
>
>   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git
>
> It's a small follow up to these commits in that same branch:
>
> commit 5e20962a9fc8 ("rust: pci: provide access to PCI Vendor values")
> commit ed78a01887e2 ("rust: pci: provide access to PCI Class and Class-related items")
>
> Danilo, I've added your Suggested-by to these.
>
> John Hubbard (2):
>   rust: pci: display symbolic PCI class names
>   rust: pci: display symbolic PCI vendor names
>
>  rust/kernel/pci/id.rs | 36 +++++++++++++++++++++++-------------
>  1 file changed, 23 insertions(+), 13 deletions(-)

The series,

Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/2] rust: pci: display symbolic PCI vendor and class names
  2025-09-25  1:33 [PATCH 0/2] rust: pci: display symbolic PCI vendor and class names John Hubbard
                   ` (2 preceding siblings ...)
  2025-09-25  3:01 ` [PATCH 0/2] rust: pci: display symbolic PCI vendor and class names Alexandre Courbot
@ 2025-09-25 16:04 ` Danilo Krummrich
  2025-09-25 23:28   ` John Hubbard
  3 siblings, 1 reply; 8+ messages in thread
From: Danilo Krummrich @ 2025-09-25 16:04 UTC (permalink / raw)
  To: John Hubbard
  Cc: Alexandre Courbot, Joel Fernandes, Timur Tabi, Alistair Popple,
	David Airlie, Simona Vetter, Bjorn Helgaas,
	Krzysztof Wilczyński, Miguel Ojeda, Alex Gaynor, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, nouveau, linux-pci, rust-for-linux,
	LKML

On Thu Sep 25, 2025 at 3:33 AM CEST, John Hubbard wrote:
> This applies to:
>
>   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git

This is an old tree, the new one is:

https://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git/

> John Hubbard (2):

Applied to driver-core-testing, thanks!

>   rust: pci: display symbolic PCI class names
>   rust: pci: display symbolic PCI vendor names

    [ Remove #[inline] for Vendor::fmt(). - Danilo ]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/2] rust: pci: display symbolic PCI vendor and class names
  2025-09-25  3:01 ` [PATCH 0/2] rust: pci: display symbolic PCI vendor and class names Alexandre Courbot
@ 2025-09-25 23:27   ` John Hubbard
  0 siblings, 0 replies; 8+ messages in thread
From: John Hubbard @ 2025-09-25 23:27 UTC (permalink / raw)
  To: Alexandre Courbot, Danilo Krummrich
  Cc: Joel Fernandes, Timur Tabi, Alistair Popple, David Airlie,
	Simona Vetter, Bjorn Helgaas, Krzysztof Wilczyński,
	Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, nouveau, linux-pci, rust-for-linux, LKML

On 9/24/25 8:01 PM, Alexandre Courbot wrote:
> On Thu Sep 25, 2025 at 10:33 AM JST, John Hubbard wrote:
>> Hi,
>>
>> This applies to:
>>
>>   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git
>>
>> It's a small follow up to these commits in that same branch:
>>
>> commit 5e20962a9fc8 ("rust: pci: provide access to PCI Vendor values")
>> commit ed78a01887e2 ("rust: pci: provide access to PCI Class and Class-related items")
>>
>> Danilo, I've added your Suggested-by to these.
>>
>> John Hubbard (2):
>>   rust: pci: display symbolic PCI class names
>>   rust: pci: display symbolic PCI vendor names
>>
>>  rust/kernel/pci/id.rs | 36 +++++++++++++++++++++++-------------
>>  1 file changed, 23 insertions(+), 13 deletions(-)
> 
> The series,
> 
> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>

Thanks for the review, Alex!


thanks,
-- 
John Hubbard


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/2] rust: pci: display symbolic PCI vendor and class names
  2025-09-25 16:04 ` Danilo Krummrich
@ 2025-09-25 23:28   ` John Hubbard
  0 siblings, 0 replies; 8+ messages in thread
From: John Hubbard @ 2025-09-25 23:28 UTC (permalink / raw)
  To: Danilo Krummrich
  Cc: Alexandre Courbot, Joel Fernandes, Timur Tabi, Alistair Popple,
	David Airlie, Simona Vetter, Bjorn Helgaas,
	Krzysztof Wilczyński, Miguel Ojeda, Alex Gaynor, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, nouveau, linux-pci, rust-for-linux,
	LKML

On 9/25/25 9:04 AM, Danilo Krummrich wrote:
> On Thu Sep 25, 2025 at 3:33 AM CEST, John Hubbard wrote:
>> This applies to:
>>
>>   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git
> 
> This is an old tree, the new one is:
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git/

OK, I'll update my setups for that.

> 
>> John Hubbard (2):
> 
> Applied to driver-core-testing, thanks!
> 
>>   rust: pci: display symbolic PCI class names
>>   rust: pci: display symbolic PCI vendor names
> 
>     [ Remove #[inline] for Vendor::fmt(). - Danilo ]

Great, thanks!


--John Hubbard


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-09-25 23:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-25  1:33 [PATCH 0/2] rust: pci: display symbolic PCI vendor and class names John Hubbard
2025-09-25  1:33 ` [PATCH 1/2] rust: pci: display symbolic PCI " John Hubbard
2025-09-25  1:33 ` [PATCH 2/2] rust: pci: display symbolic PCI vendor names John Hubbard
2025-09-25  1:38   ` John Hubbard
2025-09-25  3:01 ` [PATCH 0/2] rust: pci: display symbolic PCI vendor and class names Alexandre Courbot
2025-09-25 23:27   ` John Hubbard
2025-09-25 16:04 ` Danilo Krummrich
2025-09-25 23:28   ` John Hubbard

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).