[Devel] [PATCH vz10 v3 03/11] ext4: check nr_files early in ext4_sync_files
Konstantin Khorenko
khorenko at virtuozzo.com
Fri Aug 22 22:14:09 MSK 2025
From: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
Move the nr_files check before accessing files[0] to avoid potential
null pointer dereference when nr_files is 0.
This improves safety by failing fast when there are no files to sync.
Part of rework for ext4_sync_files function.
Fixes: 26337aacaafa9 ("ext4: add mfsync support")
https://virtuozzo.atlassian.net/browse/VSTOR-107255
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
Feature: ext4: optimized sync of a set of files - mfsync()
---
fs/ext4/fsync.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/ext4/fsync.c b/fs/ext4/fsync.c
index 0a210181f20ab..f31086efb7977 100644
--- a/fs/ext4/fsync.c
+++ b/fs/ext4/fsync.c
@@ -186,14 +186,14 @@ int ext4_sync_files(struct file **files, unsigned int *flags, unsigned int nr_fi
int need_barrier = 0;
int ret;
+ if (!nr_files)
+ return 0;
sb = files[0]->f_mapping->host->i_sb;
ret = ext4_emergency_state(sb);
if (unlikely(ret))
return ret;
J_ASSERT(ext4_journal_current_handle() == NULL);
- if (!nr_files)
- return 0;
journal = EXT4_SB(sb)->s_journal;
if (sb_rdonly(sb)) {
--
2.43.0
More information about the Devel
mailing list