From: Nithurshen <nithurshen.dev@gmail.com>
To: linux-erofs@lists.ozlabs.org
Cc: xiang@kernel.org, hsiangkao@linux.alibaba.com,
zhaoyifan28@huawei.com, stopire@gmail.com,
Nithurshen <nithurshen.dev@gmail.com>
Subject: [PATCH v3] erofs-utils: fix thread join loop in erofs_destroy_workqueue
Date: Wed, 18 Mar 2026 11:33:19 +0530 [thread overview]
Message-ID: <20260318060319.13191-1-nithurshen.dev@gmail.com> (raw)
In-Reply-To: <20260317043307.27575-1-nithurshen.dev@gmail.com>
Currently, `erofs_destroy_workqueue` returns immediately if a single
`pthread_join` fails. However, it does not log the failure, making it
difficult to debug if a worker thread gets stuck.
Add an error log when `pthread_join` fails. Retain the early return
behavior to safely abort the teardown process, ensuring we do not
free the synchronization primitives and worker array while threads
are potentially still alive (avoiding a use after free).
Signed-off-by: Nithurshen <nithurshen.dev@gmail.com>
---
lib/workqueue.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/lib/workqueue.c b/lib/workqueue.c
index 18ee0f9..4a1a957 100644
--- a/lib/workqueue.c
+++ b/lib/workqueue.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0
#include <pthread.h>
#include <stdlib.h>
+#include "erofs/print.h"
#include "erofs/workqueue.h"
static void *worker_thread(void *arg)
@@ -53,10 +54,14 @@ int erofs_destroy_workqueue(struct erofs_workqueue *wq)
while (wq->nworker) {
int ret = -pthread_join(wq->workers[wq->nworker - 1], NULL);
- if (ret)
+ if (ret) {
+ erofs_err("failed to join worker thread %u: %d",
+ wq->nworker - 1, ret);
return ret;
+ }
--wq->nworker;
}
+
free(wq->workers);
pthread_mutex_destroy(&wq->lock);
pthread_cond_destroy(&wq->cond_empty);
--
2.43.0
next prev parent reply other threads:[~2026-03-18 6:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Nithurshen [this message]
[not found] ` <CABra5+2gf8+T4ker-7rdABiy25VVPjPUSLjzarttxajYkjU2xg@mail.gmail.com>
2026-03-18 8:36 ` [PATCH v3] " 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=20260318060319.13191-1-nithurshen.dev@gmail.com \
--to=nithurshen.dev@gmail.com \
--cc=hsiangkao@linux.alibaba.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=stopire@gmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.