[PATCH v2 1/2] NFS: Prevent resource leak in nfs_alloc_server()

Markus Elfring <[email protected]> Sun, 14 Jun 2026 10:42:18 +0200
Newsgroups org.kernel.vger.kernel-janitors,org.kernel.vger.linux-kernel,org.kernel.vger.linux-nfs
Message-ID <[email protected]>
From: Markus Elfring <[email protected]>
Date: Sun, 14 Jun 2026 09:56:35 +0200

It was overlooked to call ida_free() after a failed nfs_alloc_iostats() call.
Thus add the missed function call in an if branch.

Fixes: 1c7251187dc067a6d460cf33ca67da9c1dd87807 ("NFS: add superblock sysfs entries")
Cc: [email protected]
Reported-by: Christophe Jaillet <[email protected]>
Closes: https://lore.kernel.org/linux-nfs/[email protected]/
Signed-off-by: Markus Elfring <[email protected]>
---
 fs/nfs/client.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/nfs/client.c b/fs/nfs/client.c
index 73b95318ba48..e15568e388f8 100644
--- a/fs/nfs/client.c
+++ b/fs/nfs/client.c
@@ -1088,6 +1088,7 @@ struct nfs_server *nfs_alloc_server(void)
 
 	server->io_stats = nfs_alloc_iostats();
 	if (!server->io_stats) {
+		ida_free(&s_sysfs_ids, server->s_sysfs_id);
 		kfree(server);
 		return NULL;
 	}
-- 
2.54.0