[PATCH] jffs2: Fix a lock leak in jffs2_flash_writev()

Bart Van Assche bvanassche at acm.org
Mon Oct 26 12:54:38 PDT 2026


jffs2_flash_writev() write-locks c->wbuf_sem near the start of the
function. If jffs2_sum_add_kvec() fails, the function returns without
unlocking c->wbuf_sem. Fix this by unlocking c->wbuf_sem before
returning. This bug has been detected by the Clang thread-safety
analyzer.

Fixes: e631ddba5887 ("[JFFS2] Add erase block summary support (mount time improvement)")
Signed-off-by: Bart Van Assche <bvanassche at acm.org>
---
 fs/jffs2/wbuf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
index 3b7803c75d58..c8fb58513783 100644
--- a/fs/jffs2/wbuf.c
+++ b/fs/jffs2/wbuf.c
@@ -904,8 +904,10 @@ int jffs2_flash_writev(struct jffs2_sb_info *c, const struct kvec *invecs,
 
 	if (jffs2_sum_active()) {
 		int res = jffs2_sum_add_kvec(c, invecs, count, (uint32_t) to);
-		if (res)
+		if (res) {
+			up_write(&c->wbuf_sem);
 			return res;
+		}
 	}
 
 	if (c->wbuf_len && ino)



More information about the linux-mtd mailing list