John Hubbard
2025-Sep-25 01:33 UTC
[PATCH 0/2] rust: pci: display symbolic PCI vendor and class names
Hi, This applies to: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git It's a small follow up to these commits in that same branch: commit 5e20962a9fc8 ("rust: pci: provide access to PCI Vendor values") commit ed78a01887e2 ("rust: pci: provide access to PCI Class and Class-related items") Danilo, I've added your Suggested-by to these. John Hubbard (2): rust: pci: display symbolic PCI class names rust: pci: display symbolic PCI vendor names rust/kernel/pci/id.rs | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) base-commit: d4a5d397c7fb1ca967e0da202cac196e7324f4ea -- 2.51.0
John Hubbard
2025-Sep-25 01:33 UTC
[PATCH 1/2] 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 at kernel.org> Signed-off-by: John Hubbard <jhubbard at nvidia.com> --- rust/kernel/pci/id.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/rust/kernel/pci/id.rs b/rust/kernel/pci/id.rs index 8ee1dc5c3057..6e081de30faf 100644 --- a/rust/kernel/pci/id.rs +++ b/rust/kernel/pci/id.rs @@ -50,6 +50,17 @@ impl Class { 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 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { } } -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] -- 2.51.0
John Hubbard
2025-Sep-25 01:33 UTC
[PATCH 2/2] 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 at kernel.org> Signed-off-by: John Hubbard <jhubbard at nvidia.com> --- 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] + 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 -- 2.51.0
Alexandre Courbot
2025-Sep-25 03:01 UTC
[PATCH 0/2] rust: pci: display symbolic PCI vendor and class names
On Thu Sep 25, 2025 at 10:33 AM JST, John Hubbard wrote:> Hi, > > This applies to: > > https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git > > It's a small follow up to these commits in that same branch: > > commit 5e20962a9fc8 ("rust: pci: provide access to PCI Vendor values") > commit ed78a01887e2 ("rust: pci: provide access to PCI Class and Class-related items") > > Danilo, I've added your Suggested-by to these. > > John Hubbard (2): > rust: pci: display symbolic PCI class names > rust: pci: display symbolic PCI vendor names > > rust/kernel/pci/id.rs | 36 +++++++++++++++++++++++------------- > 1 file changed, 23 insertions(+), 13 deletions(-)The series, Reviewed-by: Alexandre Courbot <acourbot at nvidia.com>
Danilo Krummrich
2025-Sep-25 16:04 UTC
[PATCH 0/2] rust: pci: display symbolic PCI vendor and class names
On Thu Sep 25, 2025 at 3:33 AM CEST, John Hubbard wrote:> This applies to: > > https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.gitThis is an old tree, the new one is: https://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git/> John Hubbard (2):Applied to driver-core-testing, thanks!> rust: pci: display symbolic PCI class names > rust: pci: display symbolic PCI vendor names[ Remove #[inline] for Vendor::fmt(). - Danilo ]