public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kthread: kthread_should_stop() checks if we're a kthread
@ 2023-11-20 22:15 Kent Overstreet
  2023-11-28  9:30 ` Petr Mladek
  0 siblings, 1 reply; 4+ messages in thread
From: Kent Overstreet @ 2023-11-20 22:15 UTC (permalink / raw)
  To: linux-kernel
  Cc: Kent Overstreet, Nicholas Piggin, Mike Christie, Zqiang,
	Petr Mladek

bcachefs has a fair amount of code that may or may not be running from a
kthread (it may instead be called by a userspace ioctl); having
kthread_should_stop() check if we're a kthread enables a fair bit of
cleanup and makes it safer to use.

Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Mike Christie <michael.christie@oracle.com>
Cc: Zqiang <qiang1.zhang@intel.com>
Cc: Petr Mladek <pmladek@suse.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
 kernel/kthread.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/kthread.c b/kernel/kthread.c
index 1eea53050bab..fe6090ddf414 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -155,7 +155,8 @@ void free_kthread_struct(struct task_struct *k)
  */
 bool kthread_should_stop(void)
 {
-	return test_bit(KTHREAD_SHOULD_STOP, &to_kthread(current)->flags);
+	return (current->flags & PF_KTHREAD) &&
+		test_bit(KTHREAD_SHOULD_STOP, &to_kthread(current)->flags);
 }
 EXPORT_SYMBOL(kthread_should_stop);
 
-- 
2.42.0


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

end of thread, other threads:[~2023-11-30 11:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-20 22:15 [PATCH] kthread: kthread_should_stop() checks if we're a kthread Kent Overstreet
2023-11-28  9:30 ` Petr Mladek
2023-11-28 17:40   ` Kent Overstreet
2023-11-30 11:24     ` Petr Mladek

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