Skip to content

Commit a78b94c

Browse files
Changman LeeHashcode
authored andcommitted
f2fs: fix overflow when calculating utilization on 32-bit
Use div_u64 to fix overflow when calculating utilization. *long int* is 4-bytes on 32-bit so (user blocks * 100) might be overflow if disk size is over e.g. 512GB. Signed-off-by: Changman Lee <cm224.lee@samsung.com> Reviewed-by: Namjae Jeon <namjae.jeon@samsung.com> Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
1 parent 3a4d247 commit a78b94c

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

fs/f2fs/segment.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,7 @@ static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi, int freed)
464464

465465
static inline int utilization(struct f2fs_sb_info *sbi)
466466
{
467-
return (long int)valid_user_blocks(sbi) * 100 /
468-
(long int)sbi->user_block_count;
467+
return div_u64(valid_user_blocks(sbi) * 100, sbi->user_block_count);
469468
}
470469

471470
/*

0 commit comments

Comments
 (0)