From 66a9cbc9a005abdefc14372b5e4d9e3695284ebf Mon Sep 17 00:00:00 2001 From: Chen Shu <751541594@qq.com> Date: Mon, 6 Jan 2025 09:35:16 +0800 Subject: [PATCH] fs: ext2: Fix nbytes_to_read calculation in ext2_inode_read() Fix incorrect nbytes_to_read calculation in ext2_inode_read() function. Previously nbytes_to_read was decremented by read value which caused incorrect calculation of bytes to read in subsequent iterations. Now nbytes_to_read is decremented by to_read value which represents the actual number of bytes read in current iteration. This fixes potential data corruption issues when reading files from ext2 filesystem. Signed-off-by: Chen Shu <751541594@qq.com> (cherry picked from commit 5a5f05ba4ef792ba2c1ef00c5cdfed1da2ec782e) --- subsys/fs/ext2/ext2_impl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/fs/ext2/ext2_impl.c b/subsys/fs/ext2/ext2_impl.c index 201e8cd92cbbcc..507e72f971c269 100644 --- a/subsys/fs/ext2/ext2_impl.c +++ b/subsys/fs/ext2/ext2_impl.c @@ -630,7 +630,7 @@ ssize_t ext2_inode_read(struct ext2_inode *inode, void *buf, uint32_t offset, si memcpy((uint8_t *)buf + read, inode_current_block_mem(inode) + block_off, to_read); read += to_read; - nbytes_to_read -= read; + nbytes_to_read -= to_read; offset += to_read; }