Re: [PATCH 4/8] rust: debugfs: Allow subdir creation in builder interface

Greg Kroah-Hartman
2025-04-30T12:06:19Z

On Tue, Apr 29, 2025 at 11:15:58PM +0000, Matthew Maurer wrote:
> Allows creating subdirectories in the builder intended to be cleaned up
> by `debugfs_remove` at the same time as the root.
>
> Signed-off-by: Matthew Maurer <mmaurer@google.com>
> ---
> rust/kernel/debugfs.rs | 26 ++++++++++++++++++++++++++
> 1 file changed, 26 insertions(+)
>
> diff --git a/rust/kernel/debugfs.rs b/rust/kernel/debugfs.rs
> index f6240fd056f8598d5ef06bdaf61c5c33eab5b734..6c7cf7e97741b98d2c0654d01fca3de0d8047e97 100644
> --- a/rust/kernel/debugfs.rs
> +++ b/rust/kernel/debugfs.rs
> @@ -347,6 +347,32 @@ pub fn display_file<T: Display + Sized>(&self, name: &CStr, data: &'a T) -> Resu
> core::mem::forget(unsafe { self.inner.display_file_raw(name, data)? });
> Ok(())
> }
> +
> + /// Creates a nested directory that may live as long as its parent

Ick, why make it complex?

> + ///
> + /// # Example
> + ///
> + /// ```
> + /// # use kernel::c_str;
> + /// # use kernel::debugfs::{Dir, Values};
> + /// let dir = Dir::new(c_str!("foo"), None)?;

Again, no checking please :)

> + /// let foo = KBox::pin_init(Values::attach(0, dir), GFP_KERNEL)?;
> + /// foo.as_ref().build(|_value, builder| {
> + /// builder.dir(c_str!("bar"))?;
> + /// Ok::<(), Error>(())
> + /// })?;
> + /// // foo/bar will still exist at this point in DebugFS
> + /// # Ok::<(), Error>(())

Again, no errors :)

thanks,

greg k-h