From: Changman Lee Date: Mon, 25 Feb 2013 08:38:02 +0000 (+0900) Subject: f2fs: fix overflow when calculating utilization on 32-bit X-Git-Tag: upstream/snapshot3+hdmi~5143^2~67 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=12fc760fd632a96f49e96f519c4aed4eb279bb61;p=platform%2Fadaptation%2Frenesas_rcar%2Frenesas_kernel.git 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 Reviewed-by: Namjae Jeon Signed-off-by: Jaegeuk Kim --- diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index 552dadb..e399bd4 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h @@ -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); } /*