linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] mm/kmemleak: Improve scan_should_stop() implementation
@ 2026-01-30  9:37 Zhongqiu Han
  2026-01-30  9:37 ` [PATCH 1/2] mm/kmemleak: Remove unreachable return statement in scan_should_stop() Zhongqiu Han
  2026-01-30  9:37 ` [PATCH 2/2] mm/kmemleak: Use PF_KTHREAD flag to detect kernel threads Zhongqiu Han
  0 siblings, 2 replies; 5+ messages in thread
From: Zhongqiu Han @ 2026-01-30  9:37 UTC (permalink / raw)
  To: catalin.marinas, akpm; +Cc: linux-mm, linux-kernel, zhongqiu.han

This series improves the scan_should_stop() function by addressing code
quality issues and enhancing kernel thread detection robustness.

Patch 1 removes unreachable code that serves no purpose.

Patch 2 replaces current->mm with PF_KTHREAD for more reliable and
explicit kernel thread detection.

Zhongqiu Han (2):
  mm/kmemleak: Remove unreachable return statement in scan_should_stop()
  mm/kmemleak: Use PF_KTHREAD flag to detect kernel threads

 mm/kmemleak.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)


base-commit: 33a647c659ffa5bdb94abc345c8c86768ff96215
-- 
2.43.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] mm/kmemleak: Remove unreachable return statement in scan_should_stop()
  2026-01-30  9:37 [PATCH 0/2] mm/kmemleak: Improve scan_should_stop() implementation Zhongqiu Han
@ 2026-01-30  9:37 ` Zhongqiu Han
  2026-02-03 17:55   ` Catalin Marinas
  2026-01-30  9:37 ` [PATCH 2/2] mm/kmemleak: Use PF_KTHREAD flag to detect kernel threads Zhongqiu Han
  1 sibling, 1 reply; 5+ messages in thread
From: Zhongqiu Han @ 2026-01-30  9:37 UTC (permalink / raw)
  To: catalin.marinas, akpm; +Cc: linux-mm, linux-kernel, zhongqiu.han

Remove unreachable "return 0;" statement as all execution paths return
before reaching it.

No functional change.

Signed-off-by: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
---
 mm/kmemleak.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index fe33f2edfe07..fb0022f34393 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -1509,10 +1509,8 @@ static int scan_should_stop(void)
 	 */
 	if (current->mm)
 		return signal_pending(current);
-	else
-		return kthread_should_stop();
 
-	return 0;
+	return kthread_should_stop();
 }
 
 /*
-- 
2.43.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] mm/kmemleak: Use PF_KTHREAD flag to detect kernel threads
  2026-01-30  9:37 [PATCH 0/2] mm/kmemleak: Improve scan_should_stop() implementation Zhongqiu Han
  2026-01-30  9:37 ` [PATCH 1/2] mm/kmemleak: Remove unreachable return statement in scan_should_stop() Zhongqiu Han
@ 2026-01-30  9:37 ` Zhongqiu Han
  2026-02-03 18:00   ` Catalin Marinas
  1 sibling, 1 reply; 5+ messages in thread
From: Zhongqiu Han @ 2026-01-30  9:37 UTC (permalink / raw)
  To: catalin.marinas, akpm; +Cc: linux-mm, linux-kernel, zhongqiu.han

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 use_mm() (although kmemleak does not currently encounter
such cases, this makes the code more robust).

No functional change.

Signed-off-by: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
---
 mm/kmemleak.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index fb0022f34393..eb2ffbaf2f7e 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -1507,10 +1507,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);
 }
 
 /*
-- 
2.43.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] mm/kmemleak: Remove unreachable return statement in scan_should_stop()
  2026-01-30  9:37 ` [PATCH 1/2] mm/kmemleak: Remove unreachable return statement in scan_should_stop() Zhongqiu Han
@ 2026-02-03 17:55   ` Catalin Marinas
  0 siblings, 0 replies; 5+ messages in thread
From: Catalin Marinas @ 2026-02-03 17:55 UTC (permalink / raw)
  To: Zhongqiu Han; +Cc: akpm, linux-mm, linux-kernel

On Fri, Jan 30, 2026 at 05:37:28PM +0800, Zhongqiu Han wrote:
> Remove unreachable "return 0;" statement as all execution paths return
> before reaching it.
> 
> No functional change.
> 
> Signed-off-by: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
> ---
>  mm/kmemleak.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/mm/kmemleak.c b/mm/kmemleak.c
> index fe33f2edfe07..fb0022f34393 100644
> --- a/mm/kmemleak.c
> +++ b/mm/kmemleak.c
> @@ -1509,10 +1509,8 @@ static int scan_should_stop(void)
>  	 */
>  	if (current->mm)
>  		return signal_pending(current);
> -	else
> -		return kthread_should_stop();
>  
> -	return 0;
> +	return kthread_should_stop();
>  }

Yeah, not sure how I ended up with this.

Acked-by: Catalin Marinas <catalin.marinas@arm.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] mm/kmemleak: Use PF_KTHREAD flag to detect kernel threads
  2026-01-30  9:37 ` [PATCH 2/2] mm/kmemleak: Use PF_KTHREAD flag to detect kernel threads Zhongqiu Han
@ 2026-02-03 18:00   ` Catalin Marinas
  0 siblings, 0 replies; 5+ messages in thread
From: Catalin Marinas @ 2026-02-03 18:00 UTC (permalink / raw)
  To: Zhongqiu Han; +Cc: akpm, linux-mm, linux-kernel

On Fri, Jan 30, 2026 at 05:37:29PM +0800, Zhongqiu Han wrote:
> 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 use_mm() (although kmemleak does not currently encounter
> such cases, this makes the code more robust).

Nitpick: it's called kthread_use_mm() now.

But you are right, this function is either called in a user thread
context (via a sysfs write) or from the kthread that kmemleak created
which would not use kthread_use_mm().

> No functional change.
> 
> Signed-off-by: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
> ---
>  mm/kmemleak.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/mm/kmemleak.c b/mm/kmemleak.c
> index fb0022f34393..eb2ffbaf2f7e 100644
> --- a/mm/kmemleak.c
> +++ b/mm/kmemleak.c
> @@ -1507,10 +1507,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);

Acked-by: Catalin Marinas <catalin.marinas@arm.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-02-03 18:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-30  9:37 [PATCH 0/2] mm/kmemleak: Improve scan_should_stop() implementation Zhongqiu Han
2026-01-30  9:37 ` [PATCH 1/2] mm/kmemleak: Remove unreachable return statement in scan_should_stop() Zhongqiu Han
2026-02-03 17:55   ` Catalin Marinas
2026-01-30  9:37 ` [PATCH 2/2] mm/kmemleak: Use PF_KTHREAD flag to detect kernel threads Zhongqiu Han
2026-02-03 18:00   ` Catalin Marinas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox