Skip to content

Commit 123aaf7

Browse files
kawasakiJaegeuk Kim
authored andcommitted
f2fs: Fix type of section block count variables
Commit da52f8a ("f2fs: get the right gc victim section when section has several segments") added code to count blocks of each section using variables with type 'unsigned short', which has 2 bytes size in many systems. However, the counts can be larger than the 2 bytes range and type conversion results in wrong values. Especially when the f2fs sections have blocks as many as USHRT_MAX + 1, the count is handled as 0. This triggers eternal loop in init_dirty_segmap() at mount system call. Fix this by changing the type of the variables to block_t. Fixes: da52f8a ("f2fs: get the right gc victim section when section has several segments") Signed-off-by: Shin'ichiro Kawasaki <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 34d4ddd commit 123aaf7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

fs/f2fs/segment.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ static void __locate_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno,
799799

800800
if (__is_large_section(sbi)) {
801801
unsigned int secno = GET_SEC_FROM_SEG(sbi, segno);
802-
unsigned short valid_blocks =
802+
block_t valid_blocks =
803803
get_valid_blocks(sbi, segno, true);
804804

805805
f2fs_bug_on(sbi, unlikely(!valid_blocks ||
@@ -815,7 +815,7 @@ static void __remove_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno,
815815
enum dirty_type dirty_type)
816816
{
817817
struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
818-
unsigned short valid_blocks;
818+
block_t valid_blocks;
819819

820820
if (test_and_clear_bit(segno, dirty_i->dirty_segmap[dirty_type]))
821821
dirty_i->nr_dirty[dirty_type]--;
@@ -4316,8 +4316,8 @@ static void init_dirty_segmap(struct f2fs_sb_info *sbi)
43164316
struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
43174317
struct free_segmap_info *free_i = FREE_I(sbi);
43184318
unsigned int segno = 0, offset = 0, secno;
4319-
unsigned short valid_blocks;
4320-
unsigned short blks_per_sec = BLKS_PER_SEC(sbi);
4319+
block_t valid_blocks;
4320+
block_t blks_per_sec = BLKS_PER_SEC(sbi);
43214321

43224322
while (1) {
43234323
/* find dirty segment based on free segmap */

0 commit comments

Comments
 (0)