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 8569CC7618D for ; Thu, 6 Apr 2023 11:56:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237330AbjDFL4L (ORCPT ); Thu, 6 Apr 2023 07:56:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238791AbjDFLz1 (ORCPT ); Thu, 6 Apr 2023 07:55:27 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 048C89EE8 for ; Thu, 6 Apr 2023 04:52:29 -0700 (PDT) Received: from kwepemm600013.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Psfvq2xtWzrS37; Thu, 6 Apr 2023 19:50:47 +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, 6 Apr 2023 19:52:03 +0800 Subject: Re: [PATCH 2/2] ubi: Correct the number of PEBs after a volume resize failure To: ZhaoLong Wang , , , CC: , , References: <20230406071331.1247429-1-wangzhaolong1@huawei.com> <20230406071331.1247429-3-wangzhaolong1@huawei.com> From: Zhihao Cheng Message-ID: Date: Thu, 6 Apr 2023 19:52:03 +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: <20230406071331.1247429-3-wangzhaolong1@huawei.com> Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.178.46] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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 > 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 Reviewed-by: Zhihao Cheng > --- > drivers/mtd/ubi/vmt.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > 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: >