Skip to content

Commit d1d75ea

Browse files
Chi Zhilingnamjaejeon
authored andcommitted
exfat: fix error handling for FAT table operations
Fix three error handling issues in FAT table operations: 1. Fix exfat_update_bh() to properly return errors from sync_dirty_buffer 2. Fix exfat_end_bh() to properly return errors from exfat_update_bh() and exfat_mirror_bh() 3. Fix ignored return values from exfat_chain_cont_cluster() in inode.c and namei.c These fixes ensure that FAT table write errors are properly propagated to the caller instead of being silently ignored. Signed-off-by: Chi Zhiling <chizhiling@kylinos.cn> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
1 parent 636bd62 commit d1d75ea

5 files changed

Lines changed: 16 additions & 10 deletions

File tree

fs/exfat/exfat_fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ void exfat_set_entry_time(struct exfat_sb_info *sbi, struct timespec64 *ts,
584584
u8 *tz, __le16 *time, __le16 *date, u8 *time_cs);
585585
u16 exfat_calc_chksum16(void *data, int len, u16 chksum, int type);
586586
u32 exfat_calc_chksum32(void *data, int len, u32 chksum, int type);
587-
void exfat_update_bh(struct buffer_head *bh, int sync);
587+
int exfat_update_bh(struct buffer_head *bh, int sync);
588588
int exfat_update_bhs(struct buffer_head **bhs, int nr_bhs, int sync);
589589
void exfat_chain_set(struct exfat_chain *ec, unsigned int dir,
590590
unsigned int size, unsigned char flags);

fs/exfat/fatent.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static int exfat_mirror_bh(struct super_block *sb, struct buffer_head *bh)
2525
if (!c_bh)
2626
return -ENOMEM;
2727
memcpy(c_bh->b_data, bh->b_data, sb->s_blocksize);
28-
exfat_update_bh(c_bh, sb->s_flags & SB_SYNCHRONOUS);
28+
err = exfat_update_bh(c_bh, sb->s_flags & SB_SYNCHRONOUS);
2929
brelse(c_bh);
3030
}
3131

@@ -36,10 +36,10 @@ static int exfat_end_bh(struct super_block *sb, struct buffer_head *bh)
3636
{
3737
int err;
3838

39-
exfat_update_bh(bh, sb->s_flags & SB_SYNCHRONOUS);
40-
err = exfat_mirror_bh(sb, bh);
39+
err = exfat_update_bh(bh, sb->s_flags & SB_SYNCHRONOUS);
40+
if (!err)
41+
err = exfat_mirror_bh(sb, bh);
4142
brelse(bh);
42-
4343
return err;
4444
}
4545

fs/exfat/inode.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,9 @@ static int exfat_map_cluster(struct inode *inode, unsigned int clu_offset,
204204
* so fat-chain should be synced with
205205
* alloc-bitmap
206206
*/
207-
exfat_chain_cont_cluster(sb, ei->start_clu,
208-
num_clusters);
207+
if (exfat_chain_cont_cluster(sb, ei->start_clu,
208+
num_clusters))
209+
return -EIO;
209210
ei->flags = ALLOC_FAT_CHAIN;
210211
}
211212
if (new_clu.flags == ALLOC_FAT_CHAIN)

fs/exfat/misc.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,17 @@ u32 exfat_calc_chksum32(void *data, int len, u32 chksum, int type)
161161
return chksum;
162162
}
163163

164-
void exfat_update_bh(struct buffer_head *bh, int sync)
164+
int exfat_update_bh(struct buffer_head *bh, int sync)
165165
{
166+
int err = 0;
167+
166168
set_buffer_uptodate(bh);
167169
mark_buffer_dirty(bh);
168170

169171
if (sync)
170-
sync_dirty_buffer(bh);
172+
err = sync_dirty_buffer(bh);
173+
174+
return err;
171175
}
172176

173177
int exfat_update_bhs(struct buffer_head **bhs, int nr_bhs, int sync)

fs/exfat/namei.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ int exfat_find_empty_entry(struct inode *inode,
365365
/* no-fat-chain bit is disabled,
366366
* so fat-chain should be synced with alloc-bitmap
367367
*/
368-
exfat_chain_cont_cluster(sb, p_dir->dir, p_dir->size);
368+
if (exfat_chain_cont_cluster(sb, p_dir->dir, p_dir->size))
369+
return -EIO;
369370
p_dir->flags = ALLOC_FAT_CHAIN;
370371
hint_femp.cur.flags = ALLOC_FAT_CHAIN;
371372
}

0 commit comments

Comments
 (0)