From c2d9196541fa58de16e219092f56ae507c925cac Mon Sep 17 00:00:00 2001 From: Zhongqiu Han Date: Fri, 30 Jan 2026 17:37:29 +0800 Subject: [PATCH] mm/kmemleak: use PF_KTHREAD flag to detect kernel threads Replace the current->mm check with PF_KTHREAD flag for more reliable kernel thread detection in scan_should_stop(). The PF_KTHREAD flag is the standard way to identify kernel threads and is not affected by temporary mm borrowing via kthread_use_mm() (although kmemleak does not currently encounter such cases, this makes the code more robust). No functional change. Link: https://lkml.kernel.org/r/20260130093729.2045858-3-zhongqiu.han@oss.qualcomm.com Signed-off-by: Zhongqiu Han Acked-by: Catalin Marinas Signed-off-by: Andrew Morton --- mm/kmemleak.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 2a24d9a4a835..fa8201e23222 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -1505,10 +1505,10 @@ static int scan_should_stop(void) * This function may be called from either process or kthread context, * hence the need to check for both stop conditions. */ - if (current->mm) - return signal_pending(current); + if (current->flags & PF_KTHREAD) + return kthread_should_stop(); - return kthread_should_stop(); + return signal_pending(current); } /*