public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Josh Law <hlcj1234567@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, Josh Law <objecting@objecting.org>
Subject: [PATCH v1 1/2] lib/lwq: fix potential kthread_stop() hang in test
Date: Thu, 12 Mar 2026 22:14:26 +0000	[thread overview]
Message-ID: <20260312221427.75011-2-objecting@objecting.org> (raw)
In-Reply-To: <20260312221427.75011-1-objecting@objecting.org>

From: Josh Law <objecting@objecting.org>

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@objecting.org>
---
 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


  reply	other threads:[~2026-03-12 22:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-12 22:14 [PATCH v1 0/2] lib/lwq: fixes for test module hang and unload Josh Law
2026-03-12 22:14 ` Josh Law [this message]
2026-03-12 22:14 ` [PATCH v1 2/2] lib/lwq: add missing module_exit for test module Josh Law

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260312221427.75011-2-objecting@objecting.org \
    --to=hlcj1234567@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=objecting@objecting.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox