Skip to content

Commit 36959d1

Browse files
Zhiguo NiuJaegeuk Kim
authored andcommitted
f2fs: fix to do sanity check in update_sit_entry
If GET_SEGNO return NULL_SEGNO for some unecpected case, update_sit_entry will access invalid memory address, cause system crash. It is better to do sanity check about GET_SEGNO just like update_segment_mtime & locate_dirty_segment. Also remove some redundant judgment code. Signed-off-by: Zhiguo Niu <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 42a80aa commit 36959d1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

fs/f2fs/segment.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,6 +2413,8 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
24132413
#endif
24142414

24152415
segno = GET_SEGNO(sbi, blkaddr);
2416+
if (segno == NULL_SEGNO)
2417+
return;
24162418

24172419
se = get_seg_entry(sbi, segno);
24182420
new_vblocks = se->valid_blocks + del;
@@ -3526,8 +3528,7 @@ int f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
35263528
* since SSR needs latest valid block information.
35273529
*/
35283530
update_sit_entry(sbi, *new_blkaddr, 1);
3529-
if (GET_SEGNO(sbi, old_blkaddr) != NULL_SEGNO)
3530-
update_sit_entry(sbi, old_blkaddr, -1);
3531+
update_sit_entry(sbi, old_blkaddr, -1);
35313532

35323533
/*
35333534
* If the current segment is full, flush it out and replace it with a

0 commit comments

Comments
 (0)