From 9f5685a1288804cd8aea991cc02cccaa5d35a5ae Mon Sep 17 00:00:00 2001
From: Anders Roxell <anders.roxell@linaro.org>
Date: Fri, 4 Jul 2025 08:36:17 +0200
Subject: [PATCH 3/3] scsi: iscsi: Fix IDR memory leak in transport exit

Add missing idr_destroy() call in iscsi_transport_exit() to properly free
the iscsi_ep_idr radix tree nodes. Without this, module load/unload cycles
leak 576-byte radix tree node allocations, detectable by kmemleak as:

unreferenced object (size 576):
  backtrace:
    [<ffffffff81234567>] radix_tree_node_alloc+0xa0/0xf0
    [<ffffffff81234568>] idr_get_free+0x128/0x280

The iscsi_ep_idr is initialized via DEFINE_IDR() at line 89 and used
throughout the iSCSI transport layer for endpoint ID management with
proper mutex protection via iscsi_ep_idr_mutex. The fix follows the
documented pattern in lib/idr.c and matches the cleanup approach used
by other drivers.

This leak was discovered through comprehensive module testing with cumulative
kmemleak detection across 10 load/unload iterations per module.

Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
---
 drivers/scsi/scsi_transport_iscsi.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index c75a806496d6..adbedb58930d 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -5024,6 +5024,7 @@ static void __exit iscsi_transport_exit(void)
 	class_unregister(&iscsi_endpoint_class);
 	class_unregister(&iscsi_iface_class);
 	class_unregister(&iscsi_transport_class);
+	idr_destroy(&iscsi_ep_idr);
 }
 
 module_init(iscsi_transport_init);
-- 
2.47.2

