Skip to contentSkip to conversation

refperf: Set reader_tasks to NULL after kfree()

PATCH In review Kaushlendra Kumar 2 participants 2 messages Sep 11, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 refperf: Set reader_tasks to NULL after kfree()

Set reader_tasks to NULL after kfree() in ref_scale_cleanup() to improve debugging experience with kernel debugging tools. This follows the common pattern of NULLing pointers after freeing to avoid dangling pointer issues during debugging sessions.

Setting pointers to NULL after freeing helps debugging tools like kdgb,drgn, and other kernel debuggers by providing clear indication that the memory has been freed and the pointer is no longer valid.

---
 kernel/rcu/refscale.c | 1 +
 1 file changed, 1 insertion(+)
kernel/rcu/refscale.c +1 -0
index 2bfa987f4ba9..47486dff43ca 100644
@@ -1048,6 +1048,7 @@ ref_scale_cleanup(void)
 					     reader_tasks[i].task);
 	}
 	kfree(reader_tasks);
+	reader_tasks = NULL;
 
 	torture_stop_kthread("main_task", main_task);
 
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 11 lines · Kaushlendra Kumar

Set reader_tasks to NULL after kfree() in ref_scale_cleanup() to improve debugging experience with kernel debugging tools. This follows the common pattern of NULLing pointers after freeing to avoid dangling pointer issues during debugging sessions.

Setting pointers to NULL after freeing helps debugging tools like kdgb,drgn, and other kernel debuggers by providing clear indication that the memory has been freed and the pointer is no longer valid.

Queued for further review and testing, thank you!

Thanx, Paul

Quoted 19 lines
---
 kernel/rcu/refscale.c | 1 +
 1 file changed, 1 insertion(+)
kernel/rcu/refscale.c +1 -0
index 2bfa987f4ba9..47486dff43ca 100644
@@ -1048,6 +1048,7 @@ ref_scale_cleanup(void)
 					     reader_tasks[i].task);
 	}
 	kfree(reader_tasks);
+	reader_tasks = NULL;
 
 	torture_stop_kthread("main_task", main_task);
 
Signature · 1 line
2.34.1