]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
pds_core: fix debugfs_lookup dentry leak and error handling
authorNikhil P. Rao <nikhil.rao@amd.com>
Fri, 15 May 2026 21:29:07 +0000 (21:29 +0000)
committerJakub Kicinski <kuba@kernel.org>
Wed, 20 May 2026 02:18:33 +0000 (19:18 -0700)
debugfs_lookup() returns a dentry with an elevated reference count that
must be released with dput(). The current code discards the returned
dentry without calling dput(), causing a reference leak on every
firmware reset recovery.

Additionally, when CONFIG_DEBUG_FS is disabled, debugfs_lookup()
returns ERR_PTR(-ENODEV), not NULL. The current check passes for error
pointers and would call dput() on an invalid pointer, causing a crash.

Fixes: bc90fbe0c318 ("pds_core: Rework teardown/setup flow to be more common")
Signed-off-by: Nikhil P. Rao <nikhil.rao@amd.com>
Link: https://patch.msgid.link/20260515212907.998028-3-nikhil.rao@amd.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/amd/pds_core/debugfs.c

index 04c5e3abd8d706d082c0996b2768db09be70f0ba..810a0cd9bcac83a5f996fa27c5fbce22b7bae98c 100644 (file)
@@ -64,9 +64,14 @@ DEFINE_SHOW_ATTRIBUTE(identity);
 
 void pdsc_debugfs_add_ident(struct pdsc *pdsc)
 {
+       struct dentry *dentry;
+
        /* This file will already exist in the reset flow */
-       if (debugfs_lookup("identity", pdsc->dentry))
+       dentry = debugfs_lookup("identity", pdsc->dentry);
+       if (!IS_ERR_OR_NULL(dentry)) {
+               dput(dentry);
                return;
+       }
 
        debugfs_create_file("identity", 0400, pdsc->dentry,
                            pdsc, &identity_fops);