From: Salah Triki <salah.triki@gmail.com>
To: Trond Myklebust <trondmy@kernel.org>, Anna Schumaker <anna@kernel.org>
Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
Salah Triki <salah.triki@gmail.com>
Subject: [PATCH] nfs: fix memory leak in nfs_sysfs_init if kset_register fails
Date: Sat, 31 Jan 2026 01:09:37 +0100 [thread overview]
Message-ID: <20260131000937.229276-1-salah.triki@gmail.com> (raw)
When `kset_register()` fails, it does not clean up the underlying
kobject. Calling `kfree()` directly is incorrect because the kobject
within the kset has already been initialized, and its internal
resources or reference counting must be handled properly.
As stated in the kobject documentation, once a kobject is registered
(or even just initialized), you must use `kobject_put()` instead of
`kfree()` to let the reference counting mechanism perform the cleanup
via the ktype's release callback.
This patch replaces the incorrect `kfree()` with `kobject_put()` in the
error path of `nfs_sysfs_init()`.
Fixes: 943aef2dbcf75 ("NFS: Open-code the nfs_kset
kset_create_and_add()")
Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
fs/nfs/sysfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c
index ea6e6168092b..6e39cd69ed44 100644
--- a/fs/nfs/sysfs.c
+++ b/fs/nfs/sysfs.c
@@ -59,7 +59,7 @@ int nfs_sysfs_init(void)
ret = kset_register(nfs_kset);
if (ret) {
- kfree(nfs_kset);
+ kset_put(nfs_kset);
return ret;
}
--
2.43.0
next reply other threads:[~2026-01-31 0:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-31 0:09 Salah Triki [this message]
2026-01-31 12:21 ` Benjamin Coddington
2026-01-31 16:54 ` Trond Myklebust
2026-01-31 19:17 ` Salah Triki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260131000937.229276-1-salah.triki@gmail.com \
--to=salah.triki@gmail.com \
--cc=anna@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=trondmy@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®