public inbox for linux-erofs@ozlabs.org
 help / color / mirror / Atom feed
From: Nithurshen <nithurshen.dev@gmail.com>
To: linux-erofs@lists.ozlabs.org
Cc: xiang@kernel.org, hsiangkao@linux.alibaba.com,
	zhaoyifan28@huawei.com, Nithurshen <nithurshen.dev@gmail.com>
Subject: [PATCH] erofs-utils: fix thread join loop in erofs_destroy_workqueue
Date: Tue, 17 Mar 2026 10:03:07 +0530	[thread overview]
Message-ID: <20260317043307.27575-1-nithurshen.dev@gmail.com> (raw)

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



             reply	other threads:[~2026-03-17  4:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-17  4:33 Nithurshen [this message]
2026-03-17  4:38 ` [PATCH] erofs-utils: fix thread join loop in erofs_destroy_workqueue 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

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=20260317043307.27575-1-nithurshen.dev@gmail.com \
    --to=nithurshen.dev@gmail.com \
    --cc=hsiangkao@linux.alibaba.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=xiang@kernel.org \
    --cc=zhaoyifan28@huawei.com \
    /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