From 5de6951fedb29700ace53b283ccb951c8f712d12 Mon Sep 17 00:00:00 2001 From: Zhan Xusheng Date: Tue, 31 Mar 2026 13:02:49 +0800 Subject: [PATCH] erofs: ensure all folios are managed in erofs_try_to_free_all_cached_folios() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit folio_trylock() in erofs_try_to_free_all_cached_folios() may successfully acquire the folio lock, but the subsequent check for erofs_folio_is_managed() can skip unlocking when the folio is not managed by EROFS. As Gao Xiang pointed out, this condition should not happen in practice because compressed_bvecs[] only holds valid cached folios at this point — any non-managed folio would have already been detached by z_erofs_cache_release_folio() under folio lock. Fix this by adding DBG_BUGON() to catch unexpected folios and ensure folio_unlock() is always called. Suggested-by: Gao Xiang Signed-off-by: Zhan Xusheng Reviewed-by: Gao Xiang Reviewed-by: Chunhai Guo Signed-off-by: Gao Xiang --- fs/erofs/zdata.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index fe8121df9ef2f..b566996a0d1a5 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -605,8 +605,7 @@ static int erofs_try_to_free_all_cached_folios(struct erofs_sb_info *sbi, if (!folio_trylock(folio)) return -EBUSY; - if (!erofs_folio_is_managed(sbi, folio)) - continue; + DBG_BUGON(!erofs_folio_is_managed(sbi, folio)); pcl->compressed_bvecs[i].page = NULL; folio_detach_private(folio); folio_unlock(folio); -- 2.47.3