diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2023-11-20 17:08:51 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2024-01-16 16:48:38 -0500 |
commit | c2f20a2c1b867535c536035262bdf8fe944d27b5 (patch) | |
tree | 1d462bc98c5f7b844dfa4a8b1d753124fbc66d9c | |
parent | 1543eb436a466f9211c981d688f84614c672dceb (diff) |
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 <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>
-rw-r--r-- | kernel/kthread.c | 3 |
1 files changed, 2 insertions, 1 deletions
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); |