[PATCH v2 1/2] lib/lwq: fix potential kthread_stop() hang in test
From: Josh Law
Date: Sat Mar 14 2026 - 19:51:20 EST
From: Josh Law <objecting@xxxxxxxxxxxxx>
Check kthread_should_stop() in lwq_exercise()'s wait_var_event()
so the thread can exit cleanly when kthread_stop() is called while
the queue is empty.
Signed-off-by: Josh Law <objecting@xxxxxxxxxxxxx>
---
lib/lwq.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/lib/lwq.c b/lib/lwq.c
index c1e11ba6f254..1fd2ed612c75 100644
--- a/lib/lwq.c
+++ b/lib/lwq.c
@@ -86,7 +86,10 @@ static int lwq_exercise(void *qv)
struct tnode *t;
for (cnt = 0; cnt < 10000; cnt++) {
- wait_var_event(q, (t = lwq_dequeue(q, struct tnode, n)) != NULL);
+ wait_var_event(q, (t = lwq_dequeue(q, struct tnode, n)) != NULL ||
+ kthread_should_stop());
+ if (!t)
+ break;
t->c++;
if (lwq_enqueue(&t->n, q))
wake_up_var(q);
--
2.34.1