[PATCH 1/1] fat: restore original value when fat_ent_write failed
From: Ren Wei
Date: Mon May 25 2026 - 04:57:10 EST
From: Yemu Lu <prcups@xxxxxxxx>
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.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@xxxxxxxxxx
Reported-by: Yuan Tan <yuantan098@xxxxxxxxx>
Reported-by: Yifan Wu <yifanwucs@xxxxxxxxx>
Reported-by: Juefei Pu <tomapufckgml@xxxxxxxxx>
Reported-by: Xin Liu <bird@xxxxxxxxxx>
Signed-off-by: Yemu Lu <prcups@xxxxxxxx>
Signed-off-by: Ren Wei <n05ec@xxxxxxxxxx>
---
fs/fat/misc.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/fs/fat/misc.c b/fs/fat/misc.c
index 3027ef53af21..710e2e6aa1a5 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)
--
2.52.0