summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorYemu Lu <prcups@krgm.moe>2026-05-25 16:56:49 +0800
committerAndrew Morton <akpm@linux-foundation.org>2026-07-25 21:51:28 -0700
commitc4247d69cc3930db4d1d961a37f37951b5049537 (patch)
treec9fce8a16aca645006b0511fea1622f7ee14dbbc /fs
parentc8c564b0242ae0376c37898aaffb89f34720cfce (diff)
downloadlinux-next-c4247d69cc3930db4d1d961a37f37951b5049537.tar.gz
linux-next-c4247d69cc3930db4d1d961a37f37951b5049537.zip
fat: restore original value when fat_ent_write failed
fat_ent_write() may have committed the new link to the primary FAT but then failed on the mirror copy, leaving the chain pointing to new_dclus even though the caller will free it. Restore the original value to keep the chain consistent. Link: https://lore.kernel.org/20260525085649.781643-1-n05ec@lzu.edu.cn Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Yemu Lu <prcups@krgm.moe> Signed-off-by: Ren Wei <n05ec@lzu.edu.cn> Reported-by: Yuan Tan <yuantan098@gmail.com> Reported-by: Yifan Wu <yifanwucs@gmail.com> Reported-by: Juefei Pu <tomapufckgml@gmail.com> Reported-by: Xin Liu <bird@lzu.edu.cn> Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> Cc: Christian Brauner <brauner@kernel.org> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/fat/misc.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/fs/fat/misc.c b/fs/fat/misc.c
index 3027ef53af21..2a0fea26a99a 100644
--- a/fs/fat/misc.c
+++ b/fs/fat/misc.c
@@ -133,7 +133,11 @@ int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster)
ret = fat_ent_read(inode, &fatent, last);
if (ret >= 0) {
int wait = inode_needs_sync(inode);
+ int old = ret;
+
ret = fat_ent_write(inode, &fatent, new_dclus, wait);
+ if (ret < 0)
+ fat_ent_write(inode, &fatent, old, wait);
fatent_brelse(&fatent);
}
if (ret < 0)