From patchwork Tue Feb 21 07:34:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuezhang.Mo@sony.com" X-Patchwork-Id: 13147441 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26B2DC61DA3 for ; Tue, 21 Feb 2023 07:35:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233658AbjBUHfJ (ORCPT ); Tue, 21 Feb 2023 02:35:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233656AbjBUHfE (ORCPT ); Tue, 21 Feb 2023 02:35:04 -0500 Received: from mx08-001d1705.pphosted.com (mx08-001d1705.pphosted.com [185.183.30.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B4C2A270 for ; Mon, 20 Feb 2023 23:35:03 -0800 (PST) Received: from pps.filterd (m0209323.ppops.net [127.0.0.1]) by mx08-001d1705.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 31L6sUUq013847; Tue, 21 Feb 2023 07:34:53 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sony.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=S1; bh=7ohFektqA0LiNvF7AArgLumAu2Q7Yl5BbjRcnIgmNNQ=; b=HNijkcTnxtwhh8nvQSPtpeyih3kGhP+YewqgQmYq+9+O1vKjxbKxoVKirL/bGpLUlkwW YBJw5SWQKwitX64Ovy/dPlwIWqEhTWLgkcgPJw+agdukoqrVtcWZ78o8cTAzMZSdK8K/ MK1sdKAjBH5TrPvUskI2zvXMVk5BhLX9ahNxycQF0sznUBULdm2K8Ho3OYBPHq3cPKnE m3mU6jLcp0/0LMP+3gOn6fgVm9/Mk/e1yArr0clWPRqUyzTc2W0ZprtstbQyS4iGN30g /h+FcUdMQfNpAQXW2AsWeLqs8aUXw/zNFl4b8t6SypkWUShvYJdFfX7u3blvsRmo9gdH bg== Received: from apc01-tyz-obe.outbound.protection.outlook.com (mail-tyzapc01lp2040.outbound.protection.outlook.com [104.47.110.40]) by mx08-001d1705.pphosted.com (PPS) with ESMTPS id 3ntp11tucy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Feb 2023 07:34:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VHqnycWIqkT7A6na7O8aN1GjE3Qlz7JFcmHlS7MVZKGn8b6Jary2juUKP5iUU4GHMowdIHCTBAaQ8rmIjBu9A2PwnCdLGip4egOgm882J15tLUda5Ca7irMnoYtrM+3UglQuj4Ai8qwzpKTvKNTjZx0wXOoGOR2XgKSFb7xzabJZrclT2J04V+x23HDYk5CQbgWKkdDyP3bZzR8b3C85ZjTI9tMm0d1NQOGdJ8NBOPwSbBBsVALL3zpQdHEHCY969kINXXgiajO5ESXekafD4VO+mdDAK81toYBoEfbqH9TkVvnEr3sjAPM06adsVTb6kxxbW4vGYGW8TtA0Z8zB5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7ohFektqA0LiNvF7AArgLumAu2Q7Yl5BbjRcnIgmNNQ=; b=gKppwqbNYyE+cu1Cdv0cOIPikeC5+lg63u+dqHklWcliai0isOVdXdIrdDHzuOLL9yLO235YbNG7UlMb5WeomnX28k1APtGUOtbsU8LKuFVGMSiU8suNPh8n6m2Uy/VNN4h9S7slTbc1jwqcE54DfalRsUB7y84KtDVDOVCjYpWvLlDxo20Cx5M4H0AXDSGoOQlx5FTNqiyFMrGIDusQMH9E9ZvtUFtnhAaAWaBufD3k43vxzQWRGFFf7iK217Ek8SmN4NyzPgRQFpJQwULbIzrzJkPj9E1roA8vUSWTl5qocSvKUVlYqweULLcqjL8HVI3NO9T8JqL6xo0MctZmuQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=sony.com; dmarc=pass action=none header.from=sony.com; dkim=pass header.d=sony.com; arc=none Received: from PUZPR04MB6316.apcprd04.prod.outlook.com (2603:1096:301:fc::7) by PSAPR04MB4165.apcprd04.prod.outlook.com (2603:1096:301:34::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6111.21; Tue, 21 Feb 2023 07:34:48 +0000 Received: from PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::779:3520:dde5:4941]) by PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::779:3520:dde5:4941%7]) with mapi id 15.20.6111.020; Tue, 21 Feb 2023 07:34:48 +0000 From: "Yuezhang.Mo@sony.com" To: "linkinjeon@kernel.org" , "sj1557.seo@samsung.com" CC: "linux-fsdevel@vger.kernel.org" , "Andy.Wu@sony.com" , "Wataru.Aoyama@sony.com" Subject: [PATCH 3/3] exfat: fix the newly allocated clusters are not freed in error handling Thread-Topic: [PATCH 3/3] exfat: fix the newly allocated clusters are not freed in error handling Thread-Index: AdlFxnPdDHWMMvx/Tn2pD0MXxIUl0g== Date: Tue, 21 Feb 2023 07:34:47 +0000 Message-ID: Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PUZPR04MB6316:EE_|PSAPR04MB4165:EE_ x-ms-office365-filtering-correlation-id: c7ee2cd2-bafb-40ca-ee69-08db13de1c20 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: gLU8i4PK0LUQXk1+Gg8LUVRs/wXn1rQDN6AtzI913YYMLUr5EjO2KU39Jkf1KgWjpY7qg+v/2L0fktISqRTd+4s8d+1DgtZ2Ok5DTUNlsy/BmMXhwPENpVi9sphXdwCnsD32EraktAM0177rnt+ezwShw2Z6axW/wknZ8qdTLL9mkbl7wwAuAhliC4ieVlRBV4P1NUbGhrbNArClQZ4EWbZdpntmXd9A+khQvYXHFWKX8TyT1aWFzN/9T3BxTC31T25SLv+iy+VeRIfVTrL1By48FULEUMTWY8XqRRxPFgw+id+GTY30Yx9nRp5a0XEVVfGa1ZgNw0QZkuUCZx7k793vrHjxkoWxPlWB9w6Mzt55r0lBNBMnKZ36ajaoYVYHDVmQUj0HVsNWdzBZSkXz2TbkAJEmzJPnIpEEq+QQp83qdKvYjyYyghD2i6RXxkImJxiuIaJGoURN+tg6WVTsRpyeJzSKAleDW9gk6bW6UEEaGx3p8UTrvL/ZtoYQI5ma8V4JlMCAvh7ubl/2i8P8TNgVgEBmkzv9Uve5yqetI0imP/1kIlJibMCVZxLwgObCWTqGkfCgGznN7Ty88t4PbTbxCdOpz/enRJyM8CiPdFGVzT+ZdbLRwBuHZogmnqiSd3TZXuWuEmGwBE91TLZ82QiBWNkUK8HYyoN/O1IEnDZ/L4JB36jQvOCau1HiHdZnuVN8BQ5I+S3RCXYh5RKa7A== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR04MB6316.apcprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(136003)(376002)(366004)(39860400002)(396003)(346002)(451199018)(82960400001)(122000001)(38100700002)(83380400001)(86362001)(316002)(54906003)(8936002)(5660300002)(64756008)(66476007)(8676002)(4326008)(110136005)(55016003)(41300700001)(478600001)(38070700005)(107886003)(33656002)(7696005)(76116006)(66946007)(2906002)(71200400001)(66556008)(66446008)(52536014)(9686003)(186003)(6506007)(26005);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?/JSM0haeTX34KS5QyEF6mU7DtlMh?= =?utf-8?q?EcG9P24985JpW2VBg8XAnmqgzjehWt3vmJMewlgXXUuQBKk/c1XWtxswO6Pkk6o49?= =?utf-8?q?rt79aGBjRuLICq3+PoCdakNAft9sslnwnvana9YVWvwKe5ZcEoG+DNcizLtw5BJDm?= =?utf-8?q?tNoJwU55I5HyLmAdc/CjQzIv0uzw93KYEcka+klIdONaHL+T7BZg1s1DSowrj6ZaW?= =?utf-8?q?Lc0I8f0CGCXnARaO+eiNlqCjh2NxtzvufhjaDZIESUUzDPKaWNwErxEoYJI83WOwv?= =?utf-8?q?8BOLNfqWM4l0U3QiqM0PNfIknO54Nb0iQaAOieoauUR24/FjOqeR3G84gMz7u/CZH?= =?utf-8?q?8LHbgJAbBL8gQ5A1KhHDFgQpPAEWnV8Mt12bkv61xANlcXZur6fJKHxz3IHem/Ccv?= =?utf-8?q?Jb9DUv46W0kFLHrCMrxZP7LUf+56BVsgnd5kg2azXFhifVimO2YI9zUt76nZ91Lys?= =?utf-8?q?B/KQnE+e7W2QV2hnSvCPC99nAovw09SovfFtFfLAkIbWXjELJ09DwQygsviecO2Uk?= =?utf-8?q?lbbOSrTpkPdSkGQTF19LSjWEo16d73fFPxSJubtzjFRAU6k3bR3XXvgaPJ8nXtsmm?= =?utf-8?q?tAEI61jLXWVEu4ZXuhBoPnh1tCulBui8ExFfwAsQ2nd4L8xj0YRIJQbqjWrE0coWz?= =?utf-8?q?2+/s6Zfi9hMujssB3BsTfHvgkScS2qKQVC4DnqJZXZVbn0HUIGJ0Y7VljcorUbIz/?= =?utf-8?q?rtUzAHXaipaeilOediGeAdyfpLb3PvALWUX5f7vtv6kJXjDjXE2PxGfOInFCBwsG1?= =?utf-8?q?dTJxm+a/zJrrSf808K55gMUvhUYq6yS9pvHwXxQW/RUJfwnQ96txoqfXEEyhD5oGp?= =?utf-8?q?b57Z8qe/1H+3aNSA9W61y42Qg0D7vm9L+w6ak5smtkQl1ADrFgPc8jZxlFc3Kqco5?= =?utf-8?q?a6fiEqSKL0gxKtCVipDvmyuBXLMcUtXqB8Dd+ORBIVr/FrO03es8uvXJmfHhvNAgh?= =?utf-8?q?AXss6id0lydSKkm2PkASVHAX33qjtdP+O8yg65sb4OJM5T9L7iplGLsiAvXLiw1FE?= =?utf-8?q?bQu8c/ic6MDttY2l3xsngMHPyJjQK/vLojq9Yf6M9xikiNHNHBi8yv/thGpPZE1lV?= =?utf-8?q?xzKf2MJkY0PUploXG5lcAg5w54/dv6SK0zwb/dRFCnWFFAaRWueXribgdbmaZLxst?= =?utf-8?q?myfDGPu1GvwSqPzZcHFsPpqNKvUacSSqdqf4iN2k2bvrq5v1EF8BKXW1mhySyQ6iF?= =?utf-8?q?zuDFsixYKIXixy5EynOXzTT8w7PHpgpmUZ3srqqh4M4V6FGe11iUmKw6jgJLrmNJk?= =?utf-8?q?yGriCEZeZZOUWNdoW5YGIlxpUTfFL1KLNimaGhbrN9mrpIS+UPlPT1raxnjDnTDGi?= =?utf-8?q?Ixxpp+gj4YM23toHgm1GBMvSSK18C13Cy/clvgHMKRYABRPT1iFhTHh7YpkGR1lBv?= =?utf-8?q?3mAzIb/XSR+7Ltzkk1kz1acS7OxJ3ifJWVfvbihrHM507SauDCMeKKjC7J97qXGBQ?= =?utf-8?q?NhGNzn2v62M/YQ3u2F4MWXwj0iCmu+XWQ02/hJFF9JqrHsfIk9KlSMm2YmwDQtcBy?= =?utf-8?q?8K1ZopAqqNjE?= MIME-Version: 1.0 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: GD2o/3Jz2Zd7Lb6bbHVd9gvFzGDyIFPE8c8O8BtgNPAohao0acV0PIE+FRHNpCfLuGV4+Pcb4+8PTj8GSbR7f8k2unonuPW01mSDSFgGabjaz6omr0mSgK8TRQB9zDkMNu55KinRTB+r4b8X5daLwcQY0Z4wRxQVelof39P90+0c/bffC+0xnzi/7i7j/fPBMHrmtYaihIrWqXbXl8XtBRUbzESXq27u8Knw23GCEBNx/rMiqK8hgxh6zdSQGqcIY/AFWMo4t2rsstJ10+bJ8LVNM3L/MNtMb3j40cNmMk9gZS58mscPqX5/bUbU3rdnVFFw34q3dvYzg+yW+kUb/zXX9qPOis29lhiMbL0UxEWdQ1MovyRvCaQqYxBZl5M9B5ZWRzrxM6DSn03ywVeNfI4ma3AUcl7EdE4yP3xJSWwt5G5qG2EfDfiObWqYYaf8QOJbezDkK2gNJuh12dlU9H1ndfvQ2mZ/CpR3iY1v7MM3qtasMHLR31ZptUnK9p0yCgargMoCm+1tALKU5y3jrl6iXkWMCFPAr9EcDE7zjL+gidgr24sUABjeTbXlcw823AUNwc+AM1EcXg6OKEU228y5kZ51xoj46IxJfoiLblbGtTWqRNdX7i0qtANlr+GE4cWe9nvehcAri3EbzZ4Pa9CNDl4UoEM4e1d37fQloeD1DgMgognU5F/JahEMKxyJCjBbJV7v9NPhSpEPjciVSvwnqnwUKM6n7y1IfavLBHGbPgiOGdUO0UWASbjisiJmifb83EH2ooAS8Gsk4VI6UtFUk2z00dpaHMiFOun7oq8H7b3sL64gZfOzAiC9B/k6tzNIbPbk7sBudZN5TsZN0A== X-OriginatorOrg: sony.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PUZPR04MB6316.apcprd04.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c7ee2cd2-bafb-40ca-ee69-08db13de1c20 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Feb 2023 07:34:47.8332 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 66c65d8a-9158-4521-a2d8-664963db48e4 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: ATPppy4bRa/2kzDd/FR7BO8akWsmogRICYloJh4lHzuVCjXACsZYsdoa90NXqPMLwPiZUJuS6MVjz1ZmsKjJlA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PSAPR04MB4165 X-Proofpoint-GUID: QpIgEdyqJ4yRFLvlb7Cg5VcvbNLUbdKH X-Proofpoint-ORIG-GUID: QpIgEdyqJ4yRFLvlb7Cg5VcvbNLUbdKH X-Sony-Outbound-GUID: QpIgEdyqJ4yRFLvlb7Cg5VcvbNLUbdKH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.170.22 definitions=2023-02-21_04,2023-02-20_02,2023-02-09_01 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org In error handling 'free_cluster', before num_alloc clusters allocated, p_chain->size will not updated and always 0, thus the newly allocated clusters are not freed. Signed-off-by: Yuezhang Mo Reviewed-by: Andy Wu --- fs/exfat/fatent.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/fs/exfat/fatent.c b/fs/exfat/fatent.c index b4ca533acaa9..edbd0f251da1 100644 --- a/fs/exfat/fatent.c +++ b/fs/exfat/fatent.c @@ -307,7 +307,7 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc, struct exfat_chain *p_chain, bool sync_bmap) { int ret = -ENOSPC; - unsigned int num_clusters = 0, total_cnt; + unsigned int total_cnt; unsigned int hint_clu, new_clu, last_clu = EXFAT_EOF_CLUSTER; struct super_block *sb = inode->i_sb; struct exfat_sb_info *sbi = EXFAT_SB(sb); @@ -361,7 +361,7 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc, if (new_clu != hint_clu && p_chain->flags == ALLOC_NO_FAT_CHAIN) { if (exfat_chain_cont_cluster(sb, p_chain->dir, - num_clusters)) { + p_chain->size)) { ret = -EIO; goto free_cluster; } @@ -374,8 +374,6 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc, goto free_cluster; } - num_clusters++; - /* update FAT table */ if (p_chain->flags == ALLOC_FAT_CHAIN) { if (exfat_ent_set(sb, new_clu, EXFAT_EOF_CLUSTER)) { @@ -392,13 +390,14 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc, goto free_cluster; } } + p_chain->size++; + last_clu = new_clu; - if (--num_alloc == 0) { + if (p_chain->size == num_alloc) { sbi->clu_srch_ptr = hint_clu; - sbi->used_clusters += num_clusters; + sbi->used_clusters += num_alloc; - p_chain->size += num_clusters; mutex_unlock(&sbi->bitmap_lock); return 0; } @@ -409,7 +408,7 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc, if (p_chain->flags == ALLOC_NO_FAT_CHAIN) { if (exfat_chain_cont_cluster(sb, p_chain->dir, - num_clusters)) { + p_chain->size)) { ret = -EIO; goto free_cluster; } @@ -418,8 +417,7 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc, } } free_cluster: - if (num_clusters) - __exfat_free_cluster(inode, p_chain); + __exfat_free_cluster(inode, p_chain); unlock: mutex_unlock(&sbi->bitmap_lock); return ret;