]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
rust: pci: display symbolic PCI class names
authorJohn Hubbard <jhubbard@nvidia.com>
Thu, 25 Sep 2025 01:33:58 +0000 (18:33 -0700)
committerDanilo Krummrich <dakr@kernel.org>
Thu, 25 Sep 2025 13:51:16 +0000 (15:51 +0200)
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>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
rust/kernel/pci/id.rs

index 8ee1dc5c3057f574103026e1595283603ff607e5..6e081de30faf03431f252c3d2ef412373990bfd8 100644 (file)
@@ -50,6 +50,17 @@ macro_rules! define_all_pci_classes {
                 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 @@ impl fmt::Debug for Class {
     }
 }
 
-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]