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@xxxxxxxxxx> --- 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