Re: [PATCH v2 2/9] rust: debugfs: add SeqShow trait and seq_file file operations

"Danilo Krummrich" <[email protected]> Mon, 03 Aug 2026 17:23:12 +0200
Newsgroups org.kernel.vger.rust-for-linux,dev.linux.lists.driver-core,org.freedesktop.lists.dri-devel
Message-ID <[email protected]>
On Thu Jul 30, 2026 at 7:05 PM CEST, Alvin Sun wrote:
> +/// Renders `data` into a seq_file.
> +///
> +/// `data` is the value stashed as the debugfs file's `i_private` at cre=
ation
> +/// time. `show` is invoked on each read to produce the file's contents.
> +///
> +/// `open` and `release` are optional lifecycle hooks called during file=
 open
> +/// and release. They can be used to manage the lifetime of `data` (e.g.=
,
> +/// reference counting). Default implementations are no-ops.

The open() and release() callbacks shouldn't be needed. The existing C (pro=
xy
file ops) and Rust code already ensures to wait for in-flight file operatio=
ns,
so show() can't run after debugfs_remove().

Both the existing Rust debugfs code and the DRM code use the full proxy fop=
s.

> +pub trait SeqShow<T> {
> +    /// Writes debugfs output for the file.
> +    fn show(data: &T, m: &SeqFile) -> Result;
> +
> +    /// Called during file open, before `single_open`.
> +    fn open(_data: &T) -> Result {
> +        Ok(())
> +    }
> +
> +    /// Called during file release, before `single_release`.
> +    ///
> +    /// # Safety
> +    ///
> +    /// `data` must point to valid memory, kept alive by actions taken i=
n
> +    /// [`Self::open`] (e.g., incrementing a reference count).
> +    unsafe fn release(_data: NonNull<T>) {}
> +}