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>
This commit is contained in:
parent
855318e7c0
commit
d53ea977ad
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Reference in New Issue