gpu: nova-core: use stable name() method in Chipset Display impl
Subsystems (3)
PATCH 1/1 gpu: nova-core: use stable name() method in Chipset Display impl
Chipset's Display was using Debug formatting ("{self:?}"), which is not guaranteed to be stable. Use the existing name() method instead, which provides stable lowercase strings suitable for firmware path generation.
--- drivers/gpu/nova-core/gpu.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/gpu/nova-core/gpu.rs +1 -9
@@ -107,17 +107,9 @@ pub(crate) fn arch(&self) -> Architecture { } } -// TODO -// -// The resulting strings are used to generate firmware paths, hence the -// generated strings have to be stable. -// -// Hence, replace with something like strum_macros derive(Display). -// -// For now, redirect to fmt::Debug for convenience. impl fmt::Display for Chipset {fn fmt (&self, f: &mut fmt::Formatter <'_>) -> fmt::Result { -write! (f,"{self:?}" ) +write! (f,"{}" , self.name ()) } }
base-commit: b69053dd3ffbc0d2dedbbc86182cdef6f641fe1b
Signature · 1 line
2.51.2
Danilo Krummrich
maintainerQuoted 21 lines · Maurice Hieronymus
Chipset's Display was using Debug formatting ("{self:?}"), which is not guaranteed to be stable. Use the existing
name()method instead, which provides stable lowercase strings suitable for firmware path generation.Signed-off-by Maurice Hieronymus <[email protected]>--- drivers/gpu/nova-core/gpu.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)drivers/gpu/nova-core/gpu.rs +0
-4@@ -107,17 +107,9 @@ pub(crate) fn arch(&self) -> Architecture { } } -// TODO -// -// The resulting strings are used to generate firmware paths, hence the -// generated strings have to be stable.
drivers/gpu/nova-core/gpu.rs pub(crate) fn arch(&self) -> Architecture { · line 114
Quoted 10 lines
drivers/gpu/nova-core/gpu.rs +1
-5-// -// Hence, replace with something like strum_macros derive(Display). -// -// For now, redirect to fmt::Debug for convenience. impl fmt::Display for Chipset {fn fmt (&self, f: &mut fmt::Formatter <'_>) -> fmt::Result { -write! (f,"{self:?}" ) +write! (f,"{}" , self.name ()) } }
This also converts the printed string to lowercase. While this is not that big a deal, the solution we are looking for instead is what the TODO comment says: be able to derive a Display implementation (for enums).
Now that we have syn in the kernel, this seems quite straight forward to implement. Are you interested in working on this instead?
Thanks,
Danilo
Quoted 45 lines · Danilo Krummrich
Quoted 31 lines · Maurice Hieronymus
Chipset's Display was using Debug formatting ("{self:?}"), which is not
guaranteed to be stable. Use the existingname()method instead, which
provides stable lowercase strings suitable for firmware path generation.Signed-off-by Maurice Hieronymus <[email protected]>---
drivers/gpu/nova-core/gpu.rs | 10 +---------1 file changed, 1 insertion(+), 9 deletions(-)drivers/gpu/nova- renamed from drivers/gpu/nova-core/gpu.rs +0
-0
core/gpu.rs
index629c9d2dc994..be8c882338ea100644drivers/gpu/nova-core/gpu.rs +0
-0@@ -107,17 +107,9 @@ pub(crate) fn arch(&self) -> Architecture { } }drivers/gpu/nova-core/gpu.rs +0
-3-// TODO -// -// The resulting strings are used to generate firmware paths, hence the
drivers/gpu/nova-core/gpu.rs +0
-3-// generated strings have to be stable. -// -// Hence, replace with something like strum_macros derive(Display).
drivers/gpu/nova-core/gpu.rs +0
-2-// -// For now, redirect to fmt::Debug for convenience. Quoted 6 lines
impl
fmt::Displayfor Chipset {
fnfmt(&self, f: &mut fmt::Formatter<'_>)->fmt::Result{ - write!(f, "{self:?}")
+ write!(f, "{}",self.name())
}
}This also converts the printed string to lowercase. While this is not that big a
deal, the solution we are looking for instead is what the TODO comment says: be
able to derive a Display implementation (for enums).
Quoted 4 lines
Now that we have syn in the kernel, this seems quite straight forward to
implement. Are you interested in working on this instead?
Definitely!
The Display implementation should print the enum value as it is, without changing the case, correct?
I will have a look into that and send a new patch set in the next few days.
Quoted 2 lines
Thanks,
Danilo