From b9604bde694de3dbc35fe39ce851815fed449c21 Mon Sep 17 00:00:00 2001
From: Anders Roxell <anders.roxell@linaro.org>
Date: Fri, 4 Jul 2025 08:31:32 +0200
Subject: [PATCH 1/3] pps: Fix IDR memory leak in module exit

Add missing idr_destroy() call in pps_exit() to properly free the pps_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 pps_idr is initialized via DEFINE_IDR() at line 32 and used throughout
the PPS subsystem for device ID management. The fix follows the documented
pattern in lib/idr.c and matches the cleanup approach used by other drivers
such as drivers/uio/uio.c.

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/pps/pps.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/pps/pps.c b/drivers/pps/pps.c
index 6a02245ea35f..25ed0d44b121 100644
--- a/drivers/pps/pps.c
+++ b/drivers/pps/pps.c
@@ -456,6 +456,7 @@ static void __exit pps_exit(void)
 {
 	class_destroy(pps_class);
 	__unregister_chrdev(pps_major, 0, PPS_MAX_SOURCES, "pps");
+	idr_destroy(&pps_idr);
 }
 
 static int __init pps_init(void)
-- 
2.47.2

