Re: [PATCH v11 2/7] rust: debugfs: Add support for read-only files
From: Danilo Krummrich
Date: Mon Sep 08 2025 - 06:55:08 EST
On Mon Sep 8, 2025 at 12:17 PM CEST, Greg Kroah-Hartman wrote:
> I tried using this in a "tiny" test module I had written, and I get the
> following build error:
>
> --> samples/rust/rust_debugfs2.rs:64:53
> |
> 64 | _file = root.read_only_file(c_str!("name"), &hw_soc_info.name);
> | -------------- ^^^^^^^^^^^^^^^^^ expected `&u32`, found `&&CStr`
> | |
> | arguments to this method are incorrect
> |
> = note: expected reference `&u32`
> found reference `&&'static kernel::prelude::CStr`
>
> I'm trying to "just" print a CStr, which is defined as:
>
> struct HwSocInfo {
> id: u32,
> ver: u32,
> raw_id: u32,
> foundry: u32,
> name: &'static CStr,
> }
>
> Is this just a "user is holding it wrong" error on my side, or can this api not
> handle CStr values?
What you're doing should fundamentally work.
The above error suggests that your declaration of `_file` is File<&u32> rather
than File<&'static CStr>.
Also note the double reference you create with `&hw_soc_info.name`, this should
just be `hw_soc_info.name`.
You can also test this case by applying the following diff the the sample in v5:
diff --git a/samples/rust/rust_debugfs.rs b/samples/rust/rust_debugfs.rs
index b26eea3ee723..475502f30b1a 100644
--- a/samples/rust/rust_debugfs.rs
+++ b/samples/rust/rust_debugfs.rs
@@ -59,6 +59,8 @@ struct RustDebugFs {
#[pin]
_compatible: File<CString>,
#[pin]
+ _test: File<&'static CStr>,
+ #[pin]
counter: File<AtomicUsize>,
#[pin]
inner: File<Mutex<Inner>>,
@@ -140,6 +142,7 @@ fn new(pdev: &platform::Device<Core>) -> impl PinInit<Self, Error> + '_ {
.property_read::<CString>(c_str!("compatible"))
.required_by(dev)?,
),
+ _test <- debugfs.read_only_file(c_str!("test"), c_str!("some_value")),
counter <- Self::build_counter(&debugfs),
inner <- Self::build_inner(&debugfs),
_debugfs: debugfs,