[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2025043035-married-petunia-9c1e@gregkh>
Date: Wed, 30 Apr 2025 09:57:13 +0200
From: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
To: Matthew Maurer <mmaurer@...gle.com>
Cc: Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,
Danilo Krummrich <dakr@...nel.org>,
"Rafael J. Wysocki" <rafael@...nel.org>,
Sami Tolvanen <samitolvanen@...gle.com>,
linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org
Subject: Re: [PATCH 3/8] rust: debugfs: Add scoped builder interface
On Tue, Apr 29, 2025 at 11:15:57PM +0000, Matthew Maurer wrote:
> This adds an interface which allows access to references which may not
> live indefinitely by forcing them to live at least as long as the
> DebugFS directory itself.
They can ONLY live as long as the debugfs directory lives, is that what
you mean here?
>
> Signed-off-by: Matthew Maurer <mmaurer@...gle.com>
> ---
> rust/kernel/debugfs.rs | 163 +++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 163 insertions(+)
>
> diff --git a/rust/kernel/debugfs.rs b/rust/kernel/debugfs.rs
> index b20df5fce692b3047c804f7ad5af90fc4248979b..f6240fd056f8598d5ef06bdaf61c5c33eab5b734 100644
> --- a/rust/kernel/debugfs.rs
> +++ b/rust/kernel/debugfs.rs
> @@ -12,7 +12,12 @@
> use crate::str::CStr;
> use crate::types::{ARef, AlwaysRefCounted, Opaque};
> use core::fmt::Display;
> +use core::marker::{PhantomData, PhantomPinned};
> +use core::mem::ManuallyDrop;
> +use core::ops::Deref;
> +use core::pin::Pin;
> use core::ptr::NonNull;
> +use pin_init::{pin_data, pinned_drop, PinInit};
>
> /// Handle to a DebugFS directory.
> pub struct Dir {
> @@ -117,6 +122,22 @@ pub fn display_file<T: Display + Sized>(
> &self,
> name: &CStr,
> data: &'static T,
> + ) -> Result<ARef<Self>> {
> + // SAFETY: As `data` lives for the static lifetime, it outlives the file.
> + unsafe { self.display_file_raw(name, data) }
> + }
> +
> + /// Creates a DebugFS file backed by the display implementation of the provided pointer.
> + ///
> + /// # Safety
> + /// The pointee of `data` must outlive the accessibility of the `Dir` returned by this function.
> + /// This means that before `data` may become invalid, either:
> + /// * The refcount must go to zero
> + /// * The file must be rendered inaccessible, e.g. via `debugfs_remove`
Perhaps the refcount should be the thing driving debugfs_remove()? That
might save you lots of mess overall I think.
thanks,
greg k-h
Powered by blists - more mailing lists