Skip to content

Commit 6d97171

Browse files
johnhubbardDanilo Krummrich
authored andcommitted
rust: pci: display symbolic PCI vendor names
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> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> [ Remove #[inline] for Vendor::fmt(). - Danilo ] Signed-off-by: Danilo Krummrich <dakr@kernel.org>
1 parent d53ea97 commit 6d97171

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

rust/kernel/pci/id.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,17 @@ macro_rules! define_all_pci_vendors {
135135
pub const $variant: Self = Self($binding as u16);
136136
)+
137137
}
138+
139+
impl fmt::Display for Vendor {
140+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
141+
match self {
142+
$(
143+
&Self::$variant => write!(f, stringify!($variant)),
144+
)+
145+
_ => <Self as fmt::Debug>::fmt(self, f),
146+
}
147+
}
148+
}
138149
};
139150
}
140151

@@ -160,13 +171,6 @@ impl fmt::Debug for Vendor {
160171
}
161172
}
162173

163-
impl fmt::Display for Vendor {
164-
#[inline]
165-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
166-
<Self as fmt::Debug>::fmt(self, f)
167-
}
168-
}
169-
170174
define_all_pci_classes! {
171175
NOT_DEFINED = bindings::PCI_CLASS_NOT_DEFINED, // 0x000000
172176
NOT_DEFINED_VGA = bindings::PCI_CLASS_NOT_DEFINED_VGA, // 0x000100

0 commit comments

Comments
 (0)