Skip to contentSkip to conversation

rust: pci: display symbolic PCI vendor and class names

PATCH In review John Hubbard 3 participants 8 messages Sep 25, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover rust: pci: display symbolic PCI vendor and class names

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

Signature · 1 line
2.51.0
#1 lore raw

PATCH 1/2 rust: pci: display symbolic PCI class names

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.

---
 rust/kernel/pci/id.rs | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
rust/kernel/pci/id.rs +11 -6
index 8ee1dc5c3057..6e081de30faf 100644
@@ -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]
Signature · 1 line
2.51.0
#2 lore raw

PATCH 2/2 rust: pci: display symbolic PCI vendor names

In reply to 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.

---
 rust/kernel/pci/id.rs | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
rust/kernel/pci/id.rs +12 -7
index 6e081de30faf..63db4d5f5617 100644
@@ -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
Signature · 1 line
2.51.0
#3 lore raw

Re: [PATCH 2/2] rust: pci: display symbolic PCI vendor names

Quoted 19 lines · 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.

---
 rust/kernel/pci/id.rs | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
rust/kernel/pci/id.rs +0 -0
index 6e081de30faf..63db4d5f5617 100644

rust/kernel/pci/id.rs impl Vendor { · line 140

Quoted 6 lines
rust/kernel/pci/id.rs +3 -0
@@ -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

Quoted 26 lines
rust/kernel/pci/id.rs +9 -7
+            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
reviewer Reviewed-by on the v1 series
#4 lore raw
In reply to John Hubbard
Quoted 11 lines · 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")

Quoted 8 lines

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,

#5 lore raw
Quoted 18 lines · Alexandre Courbot
Quoted 17 lines · 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

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

The series,

Thanks for the review, Alex!

thanks,

Signature · 1 line
John Hubbard
maintainer
#6 lore raw
In reply to John Hubbard
Quoted 3 lines · John Hubbard

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/

Quoted 1 line

John Hubbard (2):

Applied to driver-core-testing, thanks!

Quoted 2 lines

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

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

#7 lore raw
Quoted 8 lines · Danilo Krummrich
Quoted 3 lines · John Hubbard

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.

Quoted 9 lines
Quoted 2 lines

John Hubbard (2):

Applied to driver-core-testing, thanks!

Quoted 2 lines

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

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

Great, thanks!

--John Hubbard