[PATCH v3 10/12] f2fs: cache: support fault injection

From: Chao Yu

Date: Tue Aug 25 2026 - 09:04:07 EST


This patch adds fault injection support for metadata cache allocations
to improve error-path test coverage.
- it integrates entry allocations with FAULT_KALLOC

Signed-off-by: Chao Yu <chao@xxxxxxxxxx>
---
fs/f2fs/cache.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/fs/f2fs/cache.c b/fs/f2fs/cache.c
index 5b9055ad49b9..013433ce96dc 100644
--- a/fs/f2fs/cache.c
+++ b/fs/f2fs/cache.c
@@ -176,20 +176,24 @@ static struct f2fs_cached_block *f2fs_create_cache(
struct f2fs_cached_block_list *cache,
unsigned long index, bool nofail)
{
+ struct f2fs_sb_info *sbi = cache->sbi;
struct f2fs_cached_block *entry;
unsigned int flags = GFP_NOFS;

- if (nofail)
+ if (nofail) {
flags |= __GFP_NOFAIL;
-
- entry = kzalloc_obj(*entry, flags);
- if (!entry)
- return ERR_PTR(-ENOMEM);
-
- entry->data = kmalloc(cache->sbi->blocksize, flags);
- if (!entry->data) {
- kfree(entry);
- return ERR_PTR(-ENOMEM);
+ entry = kzalloc_obj(*entry, flags);
+ entry->data = kmalloc(sbi->blocksize, flags);
+ } else {
+ entry = f2fs_kzalloc(sbi, sizeof(*entry), flags);
+ if (!entry)
+ return ERR_PTR(-ENOMEM);
+
+ entry->data = f2fs_kmalloc(sbi, sbi->blocksize, flags);
+ if (!entry->data) {
+ kfree(entry);
+ return ERR_PTR(-ENOMEM);
+ }
}

entry->index = index;
--
2.49.0