Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1762315rwl; Thu, 6 Apr 2023 00:22:38 -0700 (PDT) X-Google-Smtp-Source: AKy350bQ5zoxCj7l+EnzUYLZTWf89wly6CtoDMWuINPa1CA2wcleUW9rJNSOlgfT/fuD1J0uj8AC X-Received: by 2002:a05:6a20:65a4:b0:de:2799:12ed with SMTP id p36-20020a056a2065a400b000de279912edmr2010287pzh.29.1680765757943; Thu, 06 Apr 2023 00:22:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680765757; cv=none; d=google.com; s=arc-20160816; b=kgWBD75nuPdzp4IPi3JjT/VrQ6WxaQc62KZKgakRcuVTGrFD2mTZP5RSCCNIYIRkGa TaGuI/coLM6R8BwDpCr/ZJRdYjuJK65nyuJfQlcQQHLWqIOi/kv984/XeU0Wc09S5oj/ vr1uW8Pw44Z1T6GJJw1iRVc3S8cs83O+EXZ0hwZ4o/x6pp28XCKX872BMTnkfj3FPwCV APnrqLvELdyWwOnxjxTqH7do8xXjSazBF0wFZxjrYal4e/glSUAu/kGNWG+OH6zzHB3Y 1sBcr5YGWCB3w0UPZgHx6pWflGeRQyeyYJocnMf3gGEwNg5WlePH49XNLRA/+nWYdqLH 694Q== 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=f1U1VY+watK8eHWXimohxQXSzGugaSGjr5o3iEJKkVk=; b=DbVlqLcrxD5MOOSQszuslGz8n2A6KzTJksr8rf5KrBrdADPePkETDjEDOZflk85HHv jKTTSfAC5chvChwoEJsfh393h6MEybLcHEAVCEDHbHbdXt2hyql02H66RK1TXA9kfVjE uANqf3wp5WOS5P/Bl5efYZpEM95LPbjEyrqn4yP2+E2ERhpix1xYounkKRkwwTehbYCo ffCo0U+RlQZtkfQrsSIK1JQv4a6EAZKDu6aUyeek+s42tLMbHRqe6Q+5I8owqHmXXKF6 vDyRcZ8ZAie2lO/OdD3nzZOafjo6cVYlOwvpEmCcDuXA9HCfFAdKOmabpIXgMGeQ44We Mf8g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 201-20020a6307d2000000b004fba35db0a7si705045pgh.160.2023.04.06.00.22.26; Thu, 06 Apr 2023 00:22:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S235819AbjDFHNq (ORCPT + 99 others); Thu, 6 Apr 2023 03:13:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235569AbjDFHNp (ORCPT ); Thu, 6 Apr 2023 03:13:45 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D019E2D6A for ; Thu, 6 Apr 2023 00:13:43 -0700 (PDT) Received: from dggpemm100009.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4PsXh76ks4z17R7c; Thu, 6 Apr 2023 15:10:15 +0800 (CST) Received: from huawei.com (10.175.101.6) by dggpemm100009.china.huawei.com (7.185.36.113) 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 15:13:41 +0800 From: ZhaoLong Wang To: , , CC: , , , Subject: [PATCH 2/2] ubi: Correct the number of PEBs after a volume resize failure Date: Thu, 6 Apr 2023 15:13:31 +0800 Message-ID: <20230406071331.1247429-3-wangzhaolong1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230406071331.1247429-1-wangzhaolong1@huawei.com> References: <20230406071331.1247429-1-wangzhaolong1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm100009.china.huawei.com (7.185.36.113) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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-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 --- 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: -- 2.31.1