[PATCH v3 1/3] gpu: nova-core: build the debugfs guard before registering the driver
From: Vladislav Zaharov
Date: Sat Sep 12 2026 - 03:24:49 EST
init() creates the debugfs root, hands it to a static, and leaves it to
DebugfsRootGuard to clear that static once the module goes away.
try_pin_init! builds fields in the order they are written, and an
initializer that fails drops only what it has already built. The guard
is written after the Registration, so a registration that fails leaves
it unbuilt and its drop never runs. Statics are not dropped either, and
the module is unloaded right after, so the "nova-core" directory outlives
everything that could remove it.
The next load then finds the name taken: debugfs_create_dir() returns
-EEXIST, which Entry keeps as it would any other pointer, and every
debugfs file of the driver silently fails to appear until the machine is
rebooted.
Build the guard first. Drops still run in declaration order, so the
driver is still unregistered before the guard clears the static.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Vladislav Zaharov <vladazaharova2018@xxxxxxxxx>
---
drivers/gpu/nova-core/nova_core.rs | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/nova-core/nova_core.rs b/drivers/gpu/nova-core/nova_core.rs
index 1133c6ce5c55..11fe1d2858a9 100644
--- a/drivers/gpu/nova-core/nova_core.rs
+++ b/drivers/gpu/nova-core/nova_core.rs
@@ -47,7 +47,8 @@ fn drop(&mut self) {
#[pin_data]
struct NovaCoreModule {
// Fields are dropped in declaration order, so `_driver` is dropped first,
- // then `_debugfs_guard` clears `DEBUGFS_ROOT`.
+ // then `_debugfs_guard` clears `DEBUGFS_ROOT`. They are initialized the
+ // other way round, see `init()`.
#[pin]
_driver: Registration<pci::Adapter<driver::NovaCoreDriver>>,
_debugfs_guard: DebugfsRootGuard,
@@ -61,9 +62,14 @@ fn init(module: &'static kernel::ThisModule) -> impl PinInit<Self, Error> {
// cannot be any concurrent access to `DEBUGFS_ROOT`.
unsafe { DEBUGFS_ROOT = Some(dir) };
+ // Fields are initialized in the order written here, and an initializer that fails drops
+ // what it has already built, so the guard goes first: should registration fail, its drop
+ // still takes `DEBUGFS_ROOT` down with it. Nothing would otherwise, as statics are never
+ // dropped and the module is unloaded right away, leaving a directory behind that the
+ // next load cannot create again.
try_pin_init!(Self {
- _driver <- Registration::new(MODULE_NAME, module),
_debugfs_guard: DebugfsRootGuard,
+ _driver <- Registration::new(MODULE_NAME, module),
})
}
}
--
2.55.0