From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754939AbbGNKO5 (ORCPT ); Tue, 14 Jul 2015 06:14:57 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:46131 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752665AbbGNKO4 (ORCPT ); Tue, 14 Jul 2015 06:14:56 -0400 X-AuditID: cbfee61a-f79516d000006302-50-55a4e11751f9 From: Chao Yu To: Jaegeuk Kim Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH v2] f2fs: fix to release inode page in get_new_data_page Date: Tue, 14 Jul 2015 18:14:06 +0800 Message-id: <00f501d0be1d$e89f08d0$b9dd1a70$@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-index: AdC+GnaEd5fbjJCJTo+WBIAabs9P2g== Content-language: zh-cn X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrBLMWRmVeSWpSXmKPExsVy+t9jQV3xh0tCDfYd07Z4sn4Ws8WlRe4W l3fNYXNg9ti0qpPNY/eCz0wenzfJBTBHcdmkpOZklqUW6dslcGW8fveEqeAlX0X/suNsDYwv ubsYOTkkBEwkOg5PZ4awxSQu3FvPBmILCUxnlNi0WrmLkQvIfsUo8ez4JkaQBJuAisTyjv9M ILYIkH1o0WV2EJtZwEOiseM7K4gtDGJ/fQo2lEVAVeLkhu8sIDavgKXEzun32SFsQYkfk++x QPRqSazfeZwJwpaX2LzmLdRBChI7zr5mhNilJ3HpQScrRI24xMYjt1gmMArMQjJqFpJRs5CM moWkZQEjyypG0dSC5ILipPRcQ73ixNzi0rx0veT83E2M4PB9JrWDcWWDxSFGAQ5GJR7eCZZL QoVYE8uKK3MPMUpwMCuJ8FpsBArxpiRWVqUW5ccXleakFh9ilOZgURLnPZnvEyokkJ5Ykpqd mlqQWgSTZeLglGpgNNo8x1Rl29oPN/1PNGyrrzbfUy+1sUlHeh4Tg+tj+9NXZUMsb8zw/XGF 1/JtflVrF5uZl+6tH1OPzyjd3n5ivTyvyY53nm92+AhP7vrtLvd5wZ/jwtMY5z7bvMGP58HG /a4VAaFWF/+fa+tjb8ua9uGbjOqSqSf16mwuP3d/8OX/5F3P5Kv/OSmxFGckGmoxFxUnAgCy PwUMWwIAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In following call path, we will pass a locked and referenced ipage pointer to get_new_data_page: - init_inode_metadata - make_empty_dir - get_new_data_page There are two exit paths in get_new_data_page when error occurs: 1) grab_cache_page fails, ipage will not be released; 2) f2fs_reserve_block fails, ipage will be released in callee. So, it's not consistent for error handling in get_new_data_page. For f2fs_reserve_block, it's not very easy to change the rule of error handling, since it's already complicated. Here we deside to choose a easy way to fix this issue: If any error occur in get_new_data_page, we will ensure releasing ipage in this function. Signed-off-by: Chao Yu --- v2: * add comments in commit log and codes suggested by Jaegeuk. fs/f2fs/data.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 387d710..ddfc083 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -387,7 +387,8 @@ repeat: * * Also, caller should grab and release a rwsem by calling f2fs_lock_op() and * f2fs_unlock_op(). - * Note that, ipage is set only by make_empty_dir. + * Note that, ipage is set only by make_empty_dir, and if any error occur, + * ipage should be released by this function. */ struct page *get_new_data_page(struct inode *inode, struct page *ipage, pgoff_t index, bool new_i_size) @@ -398,8 +399,14 @@ struct page *get_new_data_page(struct inode *inode, int err; repeat: page = grab_cache_page(mapping, index); - if (!page) + if (!page) { + /* + * before exiting, we should make sure ipage will be released + * if any error occur. + */ + f2fs_put_page(ipage, 1); return ERR_PTR(-ENOMEM); + } set_new_dnode(&dn, inode, ipage, NULL, 0); err = f2fs_reserve_block(&dn, index); -- 2.4.2