On 9/24/25 6:33 PM, John Hubbard wrote:
> 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 <[email protected]>
> Signed-off-by: John Hubbard <[email protected]>
> ---
> rust/kernel/pci/id.rs | 19 ++++++++++++-------
> 1 file changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/rust/kernel/pci/id.rs b/rust/kernel/pci/id.rs
> index 6e081de30faf..63db4d5f5617 100644
> --- a/rust/kernel/pci/id.rs
> +++ b/rust/kernel/pci/id.rs
> @@ -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
> + 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