diff mbox series

NFS: Don't cleanup sysfs superblock entry if uninitialized

Message ID 47876afaea6c83f172bca3b1333989bbcca1aef9.1687860625.git.bcodding@redhat.com (mailing list archive)
State New, archived
Headers show
Series NFS: Don't cleanup sysfs superblock entry if uninitialized | expand

Commit Message

Benjamin Coddington June 27, 2023, 10:12 a.m. UTC
Its possible to end up in nfs_free_server() before the server's superblock
sysfs entry has been initialized, in which case calling kobject_put() will
emit a WARNING.  Check if the kobject has been initialized before cleaning
it up.

Fixes: 1c7251187dc0 ("NFS: add superblock sysfs entries")
Reported-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
---
 fs/nfs/client.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/fs/nfs/client.c b/fs/nfs/client.c
index 9aea938e4bf2..ed68aee87606 100644
--- a/fs/nfs/client.c
+++ b/fs/nfs/client.c
@@ -1010,8 +1010,10 @@  void nfs_free_server(struct nfs_server *server)
 
 	nfs_put_client(server->nfs_client);
 
-	nfs_sysfs_remove_server(server);
-	kobject_put(&server->kobj);
+	if (server->kobj.state_initialized) {
+		nfs_sysfs_remove_server(server);
+		kobject_put(&server->kobj);
+	}
 	ida_free(&s_sysfs_ids, server->s_sysfs_id);
 
 	ida_destroy(&server->lockowner_id);