[PATCH RFC 08/14] fs/erofs: use folio_attach/detach_private() instead of direct assignment

From: Zi Yan

Date: Fri Jul 31 2026 - 22:21:11 EST


erofs_onelinefolio_init/split/end() use folio->private without setting
PG_private or increase folio refcount and it works. But after PG_private is
replaced by checking folio->private in a future commit, it can break
folio_expected_ref_count(), since the folio has private data without
elevated refcount. Change it now.

It prepares for a future commit that removes PG_private.

No funtional change intended.

Assisted-by: Claude:claude-opus-4-8
Assisted-by: Codex:gpt-5
Signed-off-by: Zi Yan <ziy@xxxxxxxxxx>
To: Gao Xiang <xiang@xxxxxxxxxx>
To: Chao Yu <chao@xxxxxxxxxx>
Cc: Yue Hu <zbestahu@xxxxxxxxx>
Cc: Jeffle Xu <jefflexu@xxxxxxxxxxxxxxxxx>
Cc: Sandeep Dhavale <dhavale@xxxxxxxxxx>
Cc: Hongbo Li <hongbohbli@xxxxxxxxxxx>
Cc: Chunhai Guo <guochunhai@xxxxxxxx>
Cc: linux-erofs@xxxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
---
fs/erofs/data.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/erofs/data.c b/fs/erofs/data.c
index 9aa48c8d67d12..356665f025fb9 100644
--- a/fs/erofs/data.c
+++ b/fs/erofs/data.c
@@ -263,7 +263,8 @@ void erofs_onlinefolio_init(struct folio *folio)
void *v;
} u = { .o = ATOMIC_INIT(1) };

- folio->private = u.v; /* valid only if file-backed folio is locked */
+ /* valid only if file-backed folio is locked */
+ folio_attach_private(folio, u.v);
}

void erofs_onlinefolio_split(struct folio *folio)
@@ -284,7 +285,7 @@ void erofs_onlinefolio_end(struct folio *folio, int err, bool dirty)

if (v & (BIT(EROFS_ONLINEFOLIO_DIRTY) - 1))
return;
- folio->private = 0;
+ folio_detach_private(folio);
if (v & BIT(EROFS_ONLINEFOLIO_DIRTY))
flush_dcache_folio(folio);
folio_end_read(folio, !(v & BIT(EROFS_ONLINEFOLIO_EIO)));

--
2.53.0