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

From: Chao Yu

Date: Wed Aug 19 2026 - 23:21:03 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 173bbf3aa94c..c1e5c945391f 100644
--- a/fs/f2fs/cache.c
+++ b/fs/f2fs/cache.c
@@ -175,20 +175,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 = kzalloc(cache->sbi->blocksize, flags);
- if (!entry->data) {
- kfree(entry);
- return ERR_PTR(-ENOMEM);
+ entry = kzalloc_obj(*entry, flags);
+ entry->data = kzalloc(sbi->blocksize, flags);
+ } else {
+ entry = f2fs_kzalloc(sbi, sizeof(*entry), flags);
+ if (!entry)
+ return ERR_PTR(-ENOMEM);
+
+ entry->data = f2fs_kzalloc(sbi, sbi->blocksize, flags);
+ if (!entry->data) {
+ kfree(entry);
+ return ERR_PTR(-ENOMEM);
+ }
}

entry->index = index;
--
2.49.0