public inbox for gfs2@lists.linux.dev
 help / color / mirror / Atom feed
From: Alexander Aring <aahringo@redhat.com>
To: trondmy@kernel.org
Cc: anna@kernel.org, bcodding@redhat.com, gregkh@linuxfoundation.org,
	rafael@kernel.org, akpm@linux-foundation.org,
	linux-nfs@vger.kernel.org, gfs2@lists.linux.dev,
	linux-kernel@vger.kernel.org
Subject: [PATCH 3/4] nfs: sysfs: use kset_type_create_and_add()
Date: Thu,  3 Oct 2024 11:14:34 -0400	[thread overview]
Message-ID: <20241003151435.3753959-4-aahringo@redhat.com> (raw)
In-Reply-To: <20241003151435.3753959-1-aahringo@redhat.com>

Since we have the new udev helper kset_type_create_and_add() helper we
can use it as it allows to have an own kobj_type ktype that is necessary
for nfs for the nfs_netns_object_child_ns_type() kset type callback.

We lose some errno information related to kset_register() in probably
non-existing cases. We return always -ENOMEM as other uses of
kset_create_and_add() does.

The nfs_kset_release() can be replaced by the default udev helper
kset_release() as it does the same functionality.

Signed-off-by: Alexander Aring <aahringo@redhat.com>
---
 fs/nfs/sysfs.c | 29 +++--------------------------
 1 file changed, 3 insertions(+), 26 deletions(-)

diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c
index bf378ecd5d9f..a6584203b7ff 100644
--- a/fs/nfs/sysfs.c
+++ b/fs/nfs/sysfs.c
@@ -20,12 +20,6 @@
 
 static struct kset *nfs_kset;
 
-static void nfs_kset_release(struct kobject *kobj)
-{
-	struct kset *kset = container_of(kobj, struct kset, kobj);
-	kfree(kset);
-}
-
 static const struct kobj_ns_type_operations *nfs_netns_object_child_ns_type(
 		const struct kobject *kobj)
 {
@@ -33,35 +27,18 @@ static const struct kobj_ns_type_operations *nfs_netns_object_child_ns_type(
 }
 
 static struct kobj_type nfs_kset_type = {
-	.release = nfs_kset_release,
+	.release = kset_release,
 	.sysfs_ops = &kobj_sysfs_ops,
 	.child_ns_type = nfs_netns_object_child_ns_type,
 };
 
 int nfs_sysfs_init(void)
 {
-	int ret;
-
-	nfs_kset = kzalloc(sizeof(*nfs_kset), GFP_KERNEL);
+	nfs_kset = kset_type_create_and_add("nfs", NULL, fs_kobj,
+					    &nfs_kset_type);
 	if (!nfs_kset)
 		return -ENOMEM;
 
-	ret = kobject_set_name(&nfs_kset->kobj, "nfs");
-	if (ret) {
-		kfree(nfs_kset);
-		return ret;
-	}
-
-	nfs_kset->kobj.parent = fs_kobj;
-	nfs_kset->kobj.ktype = &nfs_kset_type;
-	nfs_kset->kobj.kset = NULL;
-
-	ret = kset_register(nfs_kset);
-	if (ret) {
-		kfree(nfs_kset);
-		return ret;
-	}
-
 	return 0;
 }
 
-- 
2.43.0


  parent reply	other threads:[~2024-10-03 15:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-03 15:14 [PATCH 0/4] nfs: kobject: use generic helpers and ownership Alexander Aring
2024-10-03 15:14 ` [PATCH 1/4] kobject: add kset_type_create_and_add() helper Alexander Aring
2024-10-03 15:14 ` [PATCH 2/4] kobject: export generic helper ops Alexander Aring
2024-10-03 15:14 ` Alexander Aring [this message]
2024-10-03 15:14 ` [PATCH 4/4] nfs: sysfs: use default get_ownership() callback Alexander Aring
2024-10-08 20:09   ` Benjamin Coddington
2024-10-09 14:56     ` Alexander Aring
2024-10-08 17:36 ` [PATCH 0/4] nfs: kobject: use generic helpers and ownership Alexander Aring
2024-10-08 20:12 ` Benjamin Coddington
2024-10-09 20:03   ` Anna Schumaker

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=20241003151435.3753959-4-aahringo@redhat.com \
    --to=aahringo@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=anna@kernel.org \
    --cc=bcodding@redhat.com \
    --cc=gfs2@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=rafael@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