summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-11-20 17:08:51 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2024-02-15 22:08:01 -0500
commit6cc00d1409ef17d3955fe20b6550eec63bb9ea20 (patch)
tree6ba7111e1d0b0c5ccf325df01aee05e85518d0d4
parent3781252387ad60f7b6ec5fca56ad15ad6167c7e7 (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.c3
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);