From: Changman Lee Subject: [PATCH] f2fs: fix overflow when calculating utilization on 32-bit Date: Mon, 25 Feb 2013 17:38:02 +0900 Message-ID: <1361781482-13034-1-git-send-email-cm224.lee@samsung.com> Cc: Changman Lee To: linux-fsdevel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Return-path: Received: from mailout2.samsung.com ([203.254.224.25]:9054 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754959Ab3BYIhG (ORCPT ); Mon, 25 Feb 2013 03:37:06 -0500 Received: from epcpsbgr5.samsung.com (u145.gpu120.samsung.co.kr [203.254.230.145]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MIR00AVJP8XWZ70@mailout2.samsung.com> for linux-fsdevel@vger.kernel.org; Mon, 25 Feb 2013 17:37:05 +0900 (KST) Sender: linux-fsdevel-owner@vger.kernel.org List-ID: 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 --- fs/f2fs/segment.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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); } /* -- 1.7.10.4