[PATCH] nvme/tcp: release socket on sock_alloc_file() failure

Wilfred Mallawa wilfred.opensource at gmail.com
Tue May 12 03:28:32 PDT 2026


From: Wilfred Mallawa <wilfred.mallawa at wdc.com>

If sock_alloc_file() fails after a sock_create_kern() in
nvme_tcp_alloc_queue(), the socket is not released.

Add sock_release() to release the socket if sock_alloc_file() fails.

Fixes: e40d4eb84089eae1 ("nvme-tcp: allocate socket file")
Signed-off-by: Wilfred Mallawa <wilfred.mallawa at wdc.com>
---
 drivers/nvme/host/tcp.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index 8e5421d2e8b9..f4b9d8acc7b1 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -1820,6 +1820,8 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,
 	sock_file = sock_alloc_file(queue->sock, O_CLOEXEC, NULL);
 	if (IS_ERR(sock_file)) {
 		ret = PTR_ERR(sock_file);
+		sock_release(queue->sock);
+		queue->sock = NULL;
 		goto err_destroy_mutex;
 	}
 
-- 
2.54.0




More information about the Linux-nvme mailing list