From mboxrd@z Thu Jan 1 00:00:00 1970 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 C264FC7EE26 for ; Thu, 4 May 2023 12:10:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230362AbjEDMKQ (ORCPT ); Thu, 4 May 2023 08:10:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230329AbjEDMKN (ORCPT ); Thu, 4 May 2023 08:10:13 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BBF75FC5 for ; Thu, 4 May 2023 05:10:08 -0700 (PDT) Received: from kwepemm600013.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4QBswV0pM9zpSt7; Thu, 4 May 2023 20:06:02 +0800 (CST) Received: from [10.174.178.46] (10.174.178.46) by kwepemm600013.china.huawei.com (7.193.23.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 4 May 2023 20:10:05 +0800 Subject: Re: [PATCH -next,V2 2/2] ubi: Correct the number of PEBs after a volume resize failure To: ZhaoLong Wang , , , CC: , , References: <20230504025354.3595768-1-wangzhaolong1@huawei.com> <20230504025354.3595768-2-wangzhaolong1@huawei.com> From: Zhihao Cheng Message-ID: <95408e5b-312c-0b51-e5b4-41fb34f552cd@huawei.com> Date: Thu, 4 May 2023 20:10:04 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20230504025354.3595768-2-wangzhaolong1@huawei.com> Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.178.46] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600013.china.huawei.com (7.193.23.68) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ÔÚ 2023/5/4 10:53, ZhaoLong Wang дµÀ: > In the error handing path `out_acc` of the ubi_resize_volume(), > when `pebs < 0`, it means that the volume table record fails to be > updated when the volume is shrinked. In this case, the number of > ubi->avail_pebs` and `ubi->rsvd_pebs` should also be restored, > otherwise the UBI will display an incorrect number of available PEBs. > > Signed-off-by: ZhaoLong Wang > --- > drivers/mtd/ubi/vmt.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > Reviewed-by: Zhihao Cheng > diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c > index 97294def01eb..990571287e84 100644 > --- a/drivers/mtd/ubi/vmt.c > +++ b/drivers/mtd/ubi/vmt.c > @@ -515,13 +515,12 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs) > out_acc: > spin_lock(&ubi->volumes_lock); > vol->reserved_pebs = reserved_pebs - pebs; > - if (pebs > 0) { > - ubi->rsvd_pebs -= pebs; > - ubi->avail_pebs += pebs; > + ubi->rsvd_pebs -= pebs; > + ubi->avail_pebs += pebs; > + if (pebs > 0) > ubi_eba_copy_table(vol, old_eba_tbl, vol->reserved_pebs); > - } else { > + else > ubi_eba_copy_table(vol, old_eba_tbl, reserved_pebs); > - } > vol->eba_tbl = old_eba_tbl; > spin_unlock(&ubi->volumes_lock); > out_free: >