From patchwork Tue Feb 28 06:07:34 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: 13154423 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 03ACDC64EC7 for ; Tue, 28 Feb 2023 06:07:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229563AbjB1GH5 (ORCPT ); Tue, 28 Feb 2023 01:07:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229529AbjB1GHz (ORCPT ); Tue, 28 Feb 2023 01:07:55 -0500 Received: from mx08-001d1705.pphosted.com (mx08-001d1705.pphosted.com [185.183.30.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 782CA10DE for ; Mon, 27 Feb 2023 22:07:51 -0800 (PST) Received: from pps.filterd (m0209318.ppops.net [127.0.0.1]) by mx08-001d1705.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 31S5nE90023203; Tue, 28 Feb 2023 06:07:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sony.com; h=from : to : cc : subject : date : message-id : mime-version : content-type : content-transfer-encoding; s=S1; bh=ynUN1zb79v0/N5HHc++2qYWCOw1XZFH+0Ow8bd/VPRI=; b=G+iXoeKQSGdFzSmWmmBJiDmSVw1fc/kyeDRAYK1e47/oalcyLPQvk7ARcyqLjYQkFrkN rS58aDwo+LRQ+/VqBVYNz0oRUGEadAYVRAl5i0ad4uhFUIfueKE8hZ5D3xpAN58nRKgV n7nf7uTx4OXCGBibmIsBPnGh9GrseCVv98hSG7bL7BN7OGZB6drByxgZz9PgA5/zq1jv SpiTOTFIaj74TNxjzab7DECovQ09pMKlgoIq6VKKCXfkpVjZwdwxSpgqOVeO8TYSo9ee qV/izhlGpxoeFPY9nR17RjOeBDSKs8Qs7hLFmnCMiPHGXJUVsikQPi1C9j1cV6BwlMVJ jQ== Received: from apc01-sg2-obe.outbound.protection.outlook.com (mail-sgaapc01lp2107.outbound.protection.outlook.com [104.47.26.107]) by mx08-001d1705.pphosted.com (PPS) with ESMTPS id 3nyb2gab0d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 28 Feb 2023 06:07:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jqh2nm4LHIXzCoCLv9Ceo5OhzYdVdGxOsmoBNyHwVzab/N1KnSdJYPzfb9P0I8xu2jjSx6cusXWhEOOVpfZUTMlU2G1zXd0mSWR/OkC5RntC91BwU39fBCJzyFaedf+cBYFl2FGL6P2dg3YpCGXKvdNdVEoGbRTqvbU3eaMMTbIBitAHLkj6d+tjVJwGFXKs5yLIXjzEOznE2TWv8sTGkkECFvizhOm/YnGqKGDtNaIf3htX49dtPr6vC2O4LjYEitC8saB1FhRUboU6xIzIG/vKt8mB1qxjTFYdqcRsmozMefPTK4knXB2sTJsEInureq4QXpsA8QYX+Pj/3snGKA== 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=ynUN1zb79v0/N5HHc++2qYWCOw1XZFH+0Ow8bd/VPRI=; b=kHdv5uB5h+U0Dcl7HwYGrt53ZEK4RzZqpAGRmiR/8LwpwIiolVGBGBcNsT1+DGbZ4UYRM2ohuZfa1Qsg54sAC7Reab56lfki4O7r/A6Kh9RPRCrgwnO2Dv8acRIdOHX9ZX8xhvAMIoBlGDTPhHMv4V+Pqvu2SkP6jUVYptvmicsoToWTVSQfh85AP//SzmwgJQiXP8o1/161HDHaRKXv+hV73NIa8zfbHM1f43Xb9f8hns6dZlCaghLsCzLzbGvbLbgeeZ2nYLB7RzM+gzQh+s5k4KaJZt+OiljmUJQLs6pjulQUeDdgKjUBgUoG4Mc6mMYgsbGsmFNfsZDyByv+Yw== 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 KL1PR0401MB4227.apcprd04.prod.outlook.com (2603:1096:820:25::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.30; Tue, 28 Feb 2023 06:07:34 +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.6134.026; Tue, 28 Feb 2023 06:07:34 +0000 From: "Yuezhang.Mo@sony.com" To: "linkinjeon@kernel.org" , "sj1557.seo@samsung.com" CC: "linux-fsdevel@vger.kernel.org" , "Wataru.Aoyama@sony.com" , "Andy.Wu@sony.com" Subject: [PATCH v2 3/3] exfat: fix the newly allocated clusters are not freed in error handling Thread-Topic: [PATCH v2 3/3] exfat: fix the newly allocated clusters are not freed in error handling Thread-Index: AdlLOtELsgz4S+exRGWgndVxY+MD7A== Date: Tue, 28 Feb 2023 06:07:34 +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_|KL1PR0401MB4227:EE_ x-ms-office365-filtering-correlation-id: 40fdee2e-acc7-4cfe-bb7b-08db19521581 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: w1Twxk0j+exicYgheyhnvh/Lc90OuFdVsndxzuSmF3NJbrb6qBdkNTepE9/CDLYhjD7fVHJnexVIojuBznwyRqXTGvFW2bGzboaRUXSnvjfhxfbrjwCvXYUgLqbDmDRthg1whs6x6Bu3t6d1b6yj7i/kvatV4LyYjV+6WeLyNemE/VD6I2WGBo2S3M+dG3kxsrMmZMD76ke0m8/nj/YmYNbu8K3G61JT5YPn0nY5m+K8ktV4aCY4K8Uk5BpXtUYB5nmdOOnlcKTh9yZ46YgBAHB3a9TZueUs6HInFZ6whaaUO/ZiYjZM00rleOSdgjAHfJupOemzEXXTzdvUx9CwTv5TdZjUvNGb65vc+8O83sww6TtB5j4wIvvEmtPsF6tDF/4hq1ljgQ3EXUBvbgG/CUaq6gWm9/QE6GtM+r4p4txgqEsfnRhmJ9dIx9Lz3431JV1xgpSpYF5Gyy6lxzBChQ8Q9MHs0MgLq4/K+A3274E3Amq18jD6X3JgBLQ76sb79nRs0ELsOcToqtyfjLEn5KJTnecu5/eA/jPat8UTRB+qzyy783241SYcqAA2ntdYdgyE1v26g8ZkSPy4zWuSS0xjBfwT7Nr1MSlYs1xLeV1+LGQWDRcT91z0mNETeqRMpbS8HPTRlDreGtLhWNALDaLiPVh88fSNvdZ4SHcX5giFzxeq9heZzbl65Tay59C8C7hocnl2uJiBh9KImM5CWA== 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)(346002)(376002)(366004)(136003)(39860400002)(396003)(451199018)(110136005)(83380400001)(33656002)(54906003)(316002)(478600001)(82960400001)(38070700005)(122000001)(7696005)(26005)(41300700001)(9686003)(186003)(71200400001)(6506007)(107886003)(5660300002)(38100700002)(76116006)(52536014)(86362001)(8936002)(2906002)(66946007)(8676002)(66476007)(66446008)(66556008)(4326008)(55016003)(64756008);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?K3KwtzZ54zvzVbRujx/9thTwwtfq?= =?utf-8?q?GpL48bgIj4ugFkJLNH7LxeRrcb46E9wEGge633hTSEDorvM2GJbcK0xKlg8lr4z0F?= =?utf-8?q?exVj/NTVFFoCSXsC1zKHFoAehYbhjFL5iQmBUBn+AZm9ejQpRUGFlpa+5sfrsqX3h?= =?utf-8?q?Bg52zB4eOKCU3GMEiK16KrSGpLITjrkLWzX4vCpKloxkuXND4KreAkgAyTRC2g74P?= =?utf-8?q?nT7Kp3mUH8JKrSivs0qJVo+COZmG0NnNWh5mKCSWhJINnEMiHdwo1iUDHEY2xEFu1?= =?utf-8?q?IPUYxbWPb85AiXuuSzvffXApkaiAg8DjALq8hyubmlSUWpCIXFTZaLnHtRVI8qmm/?= =?utf-8?q?zW3tcN1sXyayUQuffENUQ0z4NSJy13p2bJ1mjowQqRmVxLyqzQvbyG2lhp5jkRdTE?= =?utf-8?q?kPCdUZrWEBlnxJZxvNnTCSuKWa7kpyGvIrj3JJ8lquhCZhoS/QFJ5MrsNvXAYPJR9?= =?utf-8?q?n7SrPNYSXB8Kogj2l7UOQ/2my23qwrgwawtGR8c+cvJnuIHLKCBq/Y6PKg4OPEv83?= =?utf-8?q?VDTn8o2npioEbzUiXugERj9h3M82CFJMxcQUBGRWrc6DTl0P8bvuZ5JOQuVTOSLx6?= =?utf-8?q?R7ScyFKOLU1nKjXM5YZhR+OM8ZcNxuQJzRcPhbdePgqw7NfgkoEIzkcOm50lohbPz?= =?utf-8?q?dorxbnWOTptSOrwamJbUIRXJFNTw1P4xWqEFet5Udt/vtreoBJY7Ur9GAM4e/9nfG?= =?utf-8?q?5EbDA5p/3b4lwDxy9APhnTHZ5bReibUAJgGFddUBMOmxKYsAGaF5u+/a1cEipD0Vj?= =?utf-8?q?SpnvrMEZlW9RJkCiHWF3i/focExauhx85T+sRfLhRpIZv3qR1B8gHIHlp4GZTUW+2?= =?utf-8?q?beV6PHaDiVoqrjf9lkWt4iXsE1N/hbUNxktoujoeFJeX0Sjo1VIQI2/yFYutOSHyk?= =?utf-8?q?heDBaNSihcOWFlScGlsqQWxaSmOlwuBCM8oCObyJzjIQ4WihIcwotGx0ItcTszuOz?= =?utf-8?q?M8wLKBmLfbQBLWoInjj8XL4da/laAfvH3Iwbf/QFf+Pxmk17ZZdHemYkkH8Er8kbL?= =?utf-8?q?yHoQHOpaRpuN1laxDOd7J31AOC8R9nl1vKYNgnr59SGhH7x50O33T3rCF7/gdjYZy?= =?utf-8?q?y+jOQqmnPuc9FROZY52qTEMQeHNsdBk8CvpbUkWzQwQmTwV/MSaMj+Vkm2Vtx3YUQ?= =?utf-8?q?1BCVIYhYlrUhCnG50RpdJKTuzXpk9kcdIrTeyquzXsXQbXsudVzvzModNVt1YnHfi?= =?utf-8?q?yKZGugII9mYw5R6kJgCvGKzDMsxd2UCQdDdHC/hyYyHaTYzBlOpqY8yFy7XDVijr8?= =?utf-8?q?Z9VfBvghmxXY3GzwiLJAFHl3MF1HYxY+M+yhmow9z2m3Vw3UWZnr1GJb+L5gCkAgz?= =?utf-8?q?Tze0C3GyL9i5NMXp6Phs5aH/xHFnE+rglWjlaenUiZdYyoJhh8Gdj4sNMAbgqooJc?= =?utf-8?q?wW68Y3qUq6y7L9YH9khreCUVli1G0f1PzNOTnPQ03HNJHjMFTU9F5/sh0oKlevEFl?= =?utf-8?q?Z689o7yHxws2llZRfRFJCylwX8cZzROvXYbngpUO1KfmmQg/H1DJqe18wDRCfmSmN?= =?utf-8?q?AKKKFFCww2vi?= MIME-Version: 1.0 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: uckHVXbSJjmiClnp74k4eMG+fpBQ9LxGlz7NAIqmJ9dl9P533x1VEpvyqVv+O58oV2r3Pp8L9WDHq6znmn3EeWTHg/QLrVObsACiZ/LFwVWMWwN+Cygg611H3PJ4Q8QMzWSxCXg3q/vmHhHHvatkd5a+eLPgA1NQd4QKD6r14w7XG5JlmKtB7d6B9lcwfdKvEQ8X+fpHYvkgSZnuwrPhAKBhjYInyKTH6vb0FE+j15eFXcY2AQkcG04/zFHc6tDJWh8TdSZtJUQyLgro8A6IZSp1I8zep1nUP/25d/Z72rIa0kX6tRwsbf7tRhsM6otR8YcqoCE3iWgiCD8+1gKchQpTJJTJoStvnOCIUs7IebBHTvGd/Z9L0qk0Iw/wDGA3dqCM/HR4/i9UJEM1CHharGUS2j4ZU/UD0JtdOktGjnRpSLN1JukmY//BSNglI8QvanxXtU45qx0fJM6geHMpeTROSuvamGQX+OztpdwJ9OWCTJJgWYSqrXYlqRy4XXieE8YGQ62knr9AjHjl6pAyB+/5WbAG4L7n6/Z3z4Uy6ybKL42AtNQbJsM9T74p52A8sTMg/iUl8HvD7o3fTVhGKqAhxHh87y+mbGdZx5QWcWAxqCGmmNs+z27zVswnHZk4xTslG9erqfIkkYwTV8CuJ9wygiW1pso/bJUU9YnzgAHeFJOTWQTgQiiVd+/RAhIEazs3VX+3UwafD1Q3Q+BDL1ioLXPJQSl17YCXRVDmP40mGu3/oAVQmJbvRZme1GPGAHCqfgXWQZ9AhzhBulUHIs+tCEm90vNiOjlFmyuH4vpqgGnKOeixGqcWDFrKPAIKzqn5QG/iYWyil+wNt8sZuA== 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: 40fdee2e-acc7-4cfe-bb7b-08db19521581 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Feb 2023 06:07:34.1424 (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: xdyGuAtg7YTAou1Lo4ub2jGH2zKM6ueuFJxMquqG3Q/TKKzEMAJQhW45Xvfp5JRzuhnheeeA00k4NDRcIh78cQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR0401MB4227 X-Proofpoint-ORIG-GUID: MVdcFcORXkaKIGPxjrSi3KTVCDU7AIMZ X-Proofpoint-GUID: MVdcFcORXkaKIGPxjrSi3KTVCDU7AIMZ X-Sony-Outbound-GUID: MVdcFcORXkaKIGPxjrSi3KTVCDU7AIMZ 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-28_02,2023-02-27_01,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 c75c5a2cad42..56b870d9cc0d 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); @@ -358,7 +358,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; } @@ -371,8 +371,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)) { @@ -389,13 +387,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; } @@ -406,7 +405,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; } @@ -415,8 +414,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;