public inbox for linux-erofs@ozlabs.org
 help / color / mirror / Atom feed
* [PATCH] erofs-utils: fix thread join loop in erofs_destroy_workqueue
@ 2026-03-17  4:33 Nithurshen
  2026-03-17  4:38 ` Nithurshen Karthikeyan
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Nithurshen @ 2026-03-17  4:33 UTC (permalink / raw)
  To: linux-erofs; +Cc: xiang, hsiangkao, zhaoyifan28, Nithurshen

Currently, erofs_destroy_workqueue returns immediately if a single
pthread_join fails. This halts the teardown process, potentially
leaving orphaned threads and leaking the workqueue's mutexes and
worker array.

Refactor the joining logic to unconditionally join all worker
threads. Capture the first error encountered, continue joining the
remaining threads, and ensure all workqueue resources are properly
freed before returning the captured error.

Signed-off-by: Nithurshen <nithurshen.dev@gmail.com>
---
 lib/workqueue.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/lib/workqueue.c b/lib/workqueue.c
index 18ee0f9..23eb460 100644
--- a/lib/workqueue.c
+++ b/lib/workqueue.c
@@ -42,6 +42,8 @@ static void *worker_thread(void *arg)
 
 int erofs_destroy_workqueue(struct erofs_workqueue *wq)
 {
+	int err = 0;
+
 	if (!wq)
 		return -EINVAL;
 
@@ -53,15 +55,17 @@ int erofs_destroy_workqueue(struct erofs_workqueue *wq)
 	while (wq->nworker) {
 		int ret = -pthread_join(wq->workers[wq->nworker - 1], NULL);
 
-		if (ret)
-			return ret;
+		if (ret && !err)
+			err = ret;
+
 		--wq->nworker;
 	}
 	free(wq->workers);
 	pthread_mutex_destroy(&wq->lock);
 	pthread_cond_destroy(&wq->cond_empty);
 	pthread_cond_destroy(&wq->cond_full);
-	return 0;
+
+	return err;
 }
 
 int erofs_alloc_workqueue(struct erofs_workqueue *wq, unsigned int nworker,
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-03-18  8:40 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-17  4:33 [PATCH] erofs-utils: fix thread join loop in erofs_destroy_workqueue Nithurshen
2026-03-17  4:38 ` Nithurshen Karthikeyan
2026-03-18  2:15 ` 赵逸凡
2026-03-18  3:10   ` Gao Xiang
2026-03-18  4:03 ` [PATCH v2] " Nithurshen
2026-03-18  4:20   ` Yifan Zhao
2026-03-18  6:03 ` [PATCH v3] " Nithurshen
     [not found]   ` <CABra5+2gf8+T4ker-7rdABiy25VVPjPUSLjzarttxajYkjU2xg@mail.gmail.com>
2026-03-18  8:36     ` Nithurshen Karthikeyan
2026-03-18  8:40       ` Gao Xiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox