Skip to content

Commit d53ea97

Browse files
johnhubbardDanilo Krummrich
authored andcommitted
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. 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>
1 parent 855318e commit d53ea97

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

rust/kernel/pci/id.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ macro_rules! define_all_pci_classes {
5050
pub const $variant: Self = Self(Self::to_24bit_class($binding));
5151
)+
5252
}
53+
54+
impl fmt::Display for Class {
55+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56+
match self {
57+
$(
58+
&Self::$variant => write!(f, stringify!($variant)),
59+
)+
60+
_ => <Self as fmt::Debug>::fmt(self, f),
61+
}
62+
}
63+
}
5364
};
5465
}
5566

@@ -87,12 +98,6 @@ impl fmt::Debug for Class {
8798
}
8899
}
89100

90-
impl fmt::Display for Class {
91-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
92-
<Self as fmt::Debug>::fmt(self, f)
93-
}
94-
}
95-
96101
impl ClassMask {
97102
/// Get the raw mask value.
98103
#[inline]

0 commit comments

Comments
 (0)