From: Jaegeuk Kim Date: Fri, 15 Mar 2013 23:34:37 +0000 (+0900) Subject: f2fs: fix not to allocate max_nid X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=04431c44e55613a91ced16c523f749c08dff91bf;p=openwrt%2Fstaging%2Fblogic.git f2fs: fix not to allocate max_nid The build_free_nid should not add free nids over nm_i->max_nid. But, there was a hole that invalid free nid was added by the following scenario. Let's suppose nm_i->max_nid = 150 and the last NAT page has 100 ~ 200 nids. build_free_nids - get_current_nat_page loads the last NAT page - scan_nat_page can add 100 ~ 200 nids -> Bug here! So, when scanning an NAT page, we should check each candidate whether it is over max_nid or not. Reviewed-by: Namjae Jeon Signed-off-by: Jaegeuk Kim --- diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index bf9172bbbb00..f7b03ba9c0d7 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -1268,6 +1268,8 @@ static int scan_nat_page(struct f2fs_nm_info *nm_i, i = start_nid % NAT_ENTRY_PER_BLOCK; for (; i < NAT_ENTRY_PER_BLOCK; i++, start_nid++) { + if (start_nid >= nm_i->max_nid) + break; blk_addr = le32_to_cpu(nat_blk->entries[i].block_addr); BUG_ON(blk_addr == NEW_ADDR); if (blk_addr == NULL_ADDR)