Skip to contentSkip to conversation

lib/lwq: fixes for test module hang and unload

PATCH New Josh Law 1 participant 3 messages Mar 12 Library code

lore
Share & tools
lore

Josh Law

author
#0 lore raw

cover lib/lwq: fixes for test module hang and unload

This series contains two fixes for the lib/lwq test module:
1. Fix a potential kthread_stop() hang by checking kthread_should_stop() inside the wait_var_event() condition.
2. Add a missing module_exit() declaration to allow the test module to be unloaded after insertion.

Josh Law (2):
lib/lwq: fix potential kthread_stop() hang in test lib/lwq: add missing module_exit for test module

 lib/lwq.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/2 lib/lwq: fix potential kthread_stop() hang in test

From: Josh Law <[email protected]>

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.

---
 lib/lwq.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/lwq.c +4 -1
index c1e11ba6f254..1fd2ed612c75 100644
@@ -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);
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 2/2 lib/lwq: add missing module_exit for test module

In reply to Josh Law

From: Josh Law <[email protected]>

module_init(lwq_test) is declared without a corresponding module_exit, preventing the module from being unloaded when built as a module.

Add an empty module_exit handler.

---
 lib/lwq.c | 5 +++++
 1 file changed, 5 insertions(+)
lib/lwq.c +5 -0
index 1fd2ed612c75..cf4d174d6898 100644
@@ -157,5 +157,10 @@ static int lwq_test(void)
 	return 0;
 }
 
+static void lwq_test_exit(void)
+{
+}
+
 module_init(lwq_test);
+module_exit(lwq_test_exit);
 #endif /* CONFIG_LWQ_TEST*/
Signature · 1 line
2.34.1