]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
f2fs: Zero f2fs_folio_state on allocation
authorNanzhe Zhao <nzzhao@126.com>
Mon, 5 Jan 2026 15:30:57 +0000 (23:30 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 7 Jan 2026 03:17:08 +0000 (03:17 +0000)
f2fs_folio_state is attached to folio->private and is expected to start
with read_pages_pending == 0.  However, the structure was allocated from
ffs_entry_slab without being fully initialized, which can leave
read_pages_pending with stale values.

Allocate the object with __GFP_ZERO so all fields are reliably zeroed at
creation time.

Signed-off-by: Nanzhe Zhao <nzzhao@126.com>
Reviewed-by: Barry Song <baohua@kernel.org>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/data.c

index 7dee58fbfc0b4852fb9c57f5a9ac13153aac1fa3..b5b39a788ee5762dd5498072dbfa03c132ad512d 100644 (file)
@@ -2399,7 +2399,8 @@ static struct f2fs_folio_state *ffs_find_or_alloc(struct folio *folio)
        if (ffs)
                return ffs;
 
-       ffs = f2fs_kmem_cache_alloc(ffs_entry_slab, GFP_NOIO, true, NULL);
+       ffs = f2fs_kmem_cache_alloc(ffs_entry_slab,
+                       GFP_NOIO | __GFP_ZERO, true, NULL);
 
        spin_lock_init(&ffs->state_lock);
        folio_attach_private(folio, ffs);