f2fs: fix overflow when calculating utilization on 32-bit
Subsystems (2)
PATCH 1/1 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 <[email protected]>
--- fs/f2fs/segment.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/f2fs/segment.h +1 -2
@@ -464,8 +464,7 @@ static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi, int freed)static inline int utilization (struct f2fs_sb_info *sbi) { -return (long int )valid_user_blocks (sbi) *100 / - (long int )sbi->user_block_count; +return div_u64 (valid_user_blocks (sbi) *100 , sbi->user_block_count); }/*
Signature · 1 line
1.7.10.4
2013/2/25, Changman Lee <[email protected]>:
Quoted 5 lines
Use
div_u64to 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 <[email protected]>
Looks good to me.
Reviewed-by Namjae Jeon <[email protected]>
Thanks.