Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp4897455rwb; Tue, 20 Sep 2022 23:32:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7BwUsquumig4r8MUVlSMrkkgXgfCjffxVnC0PyB3W8USGu2WzC2UznZOWC9pe3Q/JlJvoq X-Received: by 2002:a65:62c5:0:b0:434:d997:5848 with SMTP id m5-20020a6562c5000000b00434d9975848mr22832446pgv.603.1663741957944; Tue, 20 Sep 2022 23:32:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663741957; cv=none; d=google.com; s=arc-20160816; b=iYF5C7AaxgKDNxhxFmoBVYjxFrsnuy6iavSXCQtMS4NYmK/dUfTMXK7bQfvvzQAl3e LnCUg34FSzyeiSomJ09rdC3VQsjIK/q5oVaCTTDqQZu7imBrbkXwRASac9ZF83F3yOpA VSb9ys8ZDEvIzneRnyOtsiF8l0XOIlXq/G5LOiis22Z3h+y6E0nDfm/O4KD7XhqD6/ZE M4TQPHska7rV99vz1kAjzITi3sY7xNkqSZKT+QGIFjrtxX/b7uvr+edJRaLz5e8iDwCX o/0/U7CJF5eH8p6RmyAsZGgm7JRiTa6nK4z94Q5/qxTcp49/rIiv8pX4HeKA68sQva9s dzEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Xo+wMxQVllvDcVRdS5nAe3ImPnmh2SBIon5HSMU8Nvc=; b=R9uu+KsoZZ91WGXDBpJ1L56VZ/5Tv6HhV52BZmOE55uPKo87FIYXIIzmKRC1cwYf6b sVWaQKBiJzpzNdri2WRj0vcwVgXaQpUyrVDqfWtsR5ZL3+kioMW5gBmA6onu+VJt+38o CzDOTO84Zwly4bzk0LL+Js3DfywGEvp33aGzu8nCHoKywp4xzNZLcM1zxYjXuT1DNwgu lsPsLo/zR18rPf7AGRlTaXhz+18Lc36XByZmDZRSaDYzyvXHz7sZFJFhxDrALSUnuz/W DushiLqxGLugkZd/nJ+fbNxiBRmcx7YLLdY+iv3QGO1uCpSMwvnx90LBt8YIsUQwiTJF Z+LQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b190-20020a6367c7000000b00434d1506600si2002130pgc.240.2022.09.20.23.32.24; Tue, 20 Sep 2022 23:32:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229886AbiIUGaA (ORCPT + 99 others); Wed, 21 Sep 2022 02:30:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229831AbiIUG35 (ORCPT ); Wed, 21 Sep 2022 02:29:57 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89AC514D1B; Tue, 20 Sep 2022 23:29:55 -0700 (PDT) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MXT3D4mWzzpTjT; Wed, 21 Sep 2022 14:27:04 +0800 (CST) Received: from huawei.com (10.175.127.227) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 21 Sep 2022 14:29:52 +0800 From: Ye Bin To: , , CC: , , Ye Bin Subject: [PATCH -next v2 3/3] ext4: update 'state->fc_regions_size' after successful memory allocation Date: Wed, 21 Sep 2022 14:40:40 +0800 Message-ID: <20220921064040.3693255-4-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220921064040.3693255-1-yebin10@huawei.com> References: <20220921064040.3693255-1-yebin10@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To canpemm500010.china.huawei.com (7.192.105.118) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org To avoid to 'state->fc_regions_size' mismatch with 'state->fc_regions' when fail to reallocate 'fc_reqions',only update 'state->fc_regions_size' after 'state->fc_regions' is allocated successfully. Signed-off-by: Ye Bin --- fs/ext4/fast_commit.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index f5b0fc50ed47..694ab0627395 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -1681,14 +1681,15 @@ int ext4_fc_record_regions(struct super_block *sb, int ino, if (state->fc_regions_used == state->fc_regions_size) { struct ext4_fc_alloc_region *fc_regions; - state->fc_regions_size += - EXT4_FC_REPLAY_REALLOC_INCREMENT; fc_regions = krealloc(state->fc_regions, - state->fc_regions_size * - sizeof(struct ext4_fc_alloc_region), + sizeof(struct ext4_fc_alloc_region) * + (state->fc_regions_size + + EXT4_FC_REPLAY_REALLOC_INCREMENT), GFP_KERNEL); if (!fc_regions) return -ENOMEM; + state->fc_regions_size += + EXT4_FC_REPLAY_REALLOC_INCREMENT; state->fc_regions = fc_regions; } region = &state->fc_regions[state->fc_regions_used++]; -- 2.31.1