rust: pci: display symbolic PCI vendor and class names
cover 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
Signature · 1 line
2.51.0
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.
--- rust/kernel/pci/id.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
rust/kernel/pci/id.rs +11 -6
@@ -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]
Signature · 1 line
2.51.0
PATCH 2/2 rust: pci: display symbolic PCI vendor names
In reply to John HubbardThe 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.
--- rust/kernel/pci/id.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
rust/kernel/pci/id.rs +12 -7
@@ -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
Signature · 1 line
2.51.0
Re: [PATCH 2/2] rust: pci: display symbolic PCI vendor names
Quoted 19 lines · John Hubbard
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(-)rust/kernel/pci/id.rs +0
-0
rust/kernel/pci/id.rs impl Vendor { · line 140
Quoted 6 lines
rust/kernel/pci/id.rs +3
-0@@ -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
Quoted 26 lines
rust/kernel/pci/id.rs +9
-7+ 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
Quoted 11 lines · John Hubbard
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") commited78a01887e2("rust: pci: provide access to PCI Class and Class-related items")
Quoted 8 lines
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 namesrust/kernel/pci/id.rs | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-)
The series,
Quoted 18 lines · Alexandre Courbot
Quoted 17 lines · John Hubbard
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") commited78a01887e2("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
Quoted 6 lines
Quoted 2 lines
rust/kernel/pci/id.rs | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-)The series,
Reviewed-by Alexandre Courbot <[email protected]>
Thanks for the review, Alex!
thanks,
Signature · 1 line
John Hubbard
Danilo Krummrich
maintainerQuoted 3 lines · John Hubbard
This applies to:
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git
This is an old tree, the new one is:
https://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git/
Quoted 1 line
John Hubbard (2):
Applied to driver-core-testing, thanks!
Quoted 2 lines
rust: pci: display symbolic PCI class names
rust: pci: display symbolic PCI vendor names
[ Remove #[inline] for Vendor::fmt(). - Danilo ]
Quoted 8 lines · Danilo Krummrich
Quoted 3 lines · John Hubbard
This applies to:
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git
This is an old tree, the new one is:
https://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git/
OK, I'll update my setups for that.
Quoted 9 lines
Quoted 2 lines
John Hubbard (2):
Applied to driver-core-testing, thanks!
Quoted 2 lines
rust: pci: display symbolic PCI class names
rust: pci: display symbolic PCI vendor names[ Remove #[inline] for
Vendor::fmt(). - Danilo ]
Great, thanks!
--John Hubbard