[PATCH] NFS: Use common error handling code in nfs_sysfs_init()

From: Markus Elfring

Date: Thu Jun 11 2026 - 07:45:34 EST


From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 11 Jun 2026 13:40:30 +0200

Use an additional label so that a bit of exception handling can be better
reused at the end of this function implementation.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
---
fs/nfs/sysfs.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c
index 3a197252a132..c4ccaa6fe87f 100644
--- a/fs/nfs/sysfs.c
+++ b/fs/nfs/sysfs.c
@@ -49,22 +49,22 @@ int nfs_sysfs_init(void)
return -ENOMEM;

ret = kobject_set_name(&nfs_kset->kobj, "nfs");
- if (ret) {
- kfree(nfs_kset);
- return ret;
- }
+ if (ret)
+ goto free_kset;

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;
- }
+ if (ret)
+ goto free_kset;

return 0;
+
+free_kset:
+ kfree(nfs_kset);
+ return ret;
}

void nfs_sysfs_exit(void)
--
2.54.0