On Wed, 2026-01-28 at 20:28 -0600, Timur Tabi wrote:
> + #[allow(static_mut_refs)]
> + // SAFETY: `DEBUGFS_ROOT` is created before driver
> registration and
> cleared
> + // after driver unregistration, so no probe() can race
> with its
> modification.
> + let log_parent = unsafe { crate::DEBUGFS_ROOT.as_ref() }
> + .expect("DEBUGFS_ROOT not initialized");
> +
> + log_parent.scope(log_buffers, dev.name(), |logs, dir| {
> + dir.read_binary_file(c_str!("loginit"),
> &logs.loginit.0);
> + dir.read_binary_file(c_str!("logintr"),
> &logs.logintr.0);
> + dir.read_binary_file(c_str!("logrm"), &logs.logrm.0);
I think there might be a problem with this code that I don't know how to
resolve.
If CONFIG_NOVA_CORE_DEBUGFS=n, then DEBUGFS_ROOT is None, and so the .as_ref()
will also be
none, and the .expect will cause a panic. We don't want that.
If I remove the .expect(), then log_parent becomes None, but then the .scope()
won't compile.
I could wrap the whole thing in #[cfg(CONFIG_NOVA_CORE_DEBUGFS)], but my
understanding is that
the call to .scope() is necessary to ensure that LogBuffers is not dropped at
the end of this
function.
It seems like I'm going to need to do something like this in struct Gsp:
#[cfg(CONFIG_NOVA_CORE_DEBUGFS)]
#[pin]
logs: debugfs::Scope<LogBuffers>,
#[cfg(not(CONFIG_NOVA_CORE_DEBUGFS))]
logs: LogBuffers, // Just own them directly, no debugfs
But the design of debugfs is to have it not care if debugfs is disabled.
Any suggestions?