From c2f20a2c1b867535c536035262bdf8fe944d27b5 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Mon, 20 Nov 2023 17:08:51 -0500 Subject: kthread: kthread_should_stop() checks if we're a kthread 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 Cc: Mike Christie Cc: Zqiang Cc: Petr Mladek Signed-off-by: Kent Overstreet --- kernel/kthread.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/kthread.c b/kernel/kthread.c index c5e40830c1f2..25742c005bde 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); -- cgit v1.2.3