Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp2859488rdd; Sat, 13 Jan 2024 05:06:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IELSbn1qKX40VBut2sNZ2dALKHlJxlFwGfFbDSQUz5c7hBgQ0rB3osgo2c5e1SEpdFhONab X-Received: by 2002:a92:cda6:0:b0:360:63c0:545a with SMTP id g6-20020a92cda6000000b0036063c0545amr4302840ild.6.1705151184817; Sat, 13 Jan 2024 05:06:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705151184; cv=none; d=google.com; s=arc-20160816; b=wIAd3WYDeGA/1yvgQE/TaKWyibF7924SpPzzOpsEDW4ZdLNMdrJJywNMsm5cj3Itod v/3GOYB5rLuI8nvM+f32juP7HEWW3mmaSoGXd8CbFkOiaAE+xgVlIKSEHSQYVkzvmLFy WsY8zaj9Ou0uI17QpaDM1ufG4J/DRvCGUZ5b/x5IfBvUEmsls8mU7ZN43zaygEsr2ci2 ppBB+blTV2rW0vhaehQbeYdT3NSEwkdV4OojHBWLybLJxkoEpqdH2JEds5yMJj1bP7Jc ORQXgOQDiVz7nwxYfYIpsPnY0avsMJwosgycg3ocxXdMzk2IqZvE6MLX7Lkt0q6oe52U VvpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=j/UD9gFxlkOLLxxVokj2DZlmkqloo2L5mGUGjuU6Onw=; fh=2bNNdPeqe+glplPbdIwHrQu+TuTraw9owaEZsd4Qncs=; b=r6t91jQc3NUAAXcliX9nmEL2kDq8MNVx78kswkI0BzEnoBGD6ejQsoLC9GV1omKBFH 4M1Zqwi5YHcK0KcASbVByKap+p7vjwMYUpcTW1FYELgyY/CfZq0zUYmf7GSM626PzUBZ CBnWTJRHxY18Ygm9Wax0iMTA0WQBLLyA8RVZKv51r+gok9vETQgFhstu1QEOb/d/pjMP OGqlBWgeUDRqLBfvpjmQV+BX+fPjxNQqElcfim5pvb5O7AwUWnm5RAC7DDPnrTIQFDiG wSsGXhlGGQja7j5wxgjYGrPg6ftcF6JrYiyPRjhH2ACdwps10E9oEyOtnuNIJfRI4y6R Lk0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-25288-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25288-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id r198-20020a632bcf000000b005cdb0648eb8si5112096pgr.508.2024.01.13.05.06.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jan 2024 05:06:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-25288-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-25288-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25288-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id A8BE7B22127 for ; Sat, 13 Jan 2024 13:06:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9550321119; Sat, 13 Jan 2024 13:06:13 +0000 (UTC) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7359D210E3 for ; Sat, 13 Jan 2024 13:06:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4TBzCm6myXz1xmCm; Sat, 13 Jan 2024 21:05:24 +0800 (CST) Received: from dggpemd200001.china.huawei.com (unknown [7.185.36.224]) by mail.maildlp.com (Postfix) with ESMTPS id A074C1404F7; Sat, 13 Jan 2024 21:06:05 +0800 (CST) Received: from huawei.com (10.175.101.6) by dggpemd200001.china.huawei.com (7.185.36.224) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.28; Sat, 13 Jan 2024 21:06:05 +0800 From: ZhaoLong Wang To: , , CC: , , , Subject: [PATCH v3 2/2] ubi: Correct the number of PEBs after a volume resize failure Date: Sat, 13 Jan 2024 21:06:01 +0800 Message-ID: <20240113130601.2502095-2-wangzhaolong1@huawei.com> X-Mailer: git-send-email 2.34.3 In-Reply-To: <20240113130601.2502095-1-wangzhaolong1@huawei.com> References: <20240113130601.2502095-1-wangzhaolong1@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemd200001.china.huawei.com (7.185.36.224) In the error handling path `out_acc` of `ubi_resize_volume()`, when `pebs < 0`, it indicates that the volume table record failed to update when the volume was shrunk. In this case, the number of `ubi->avail_pebs` and `ubi->rsvd_pebs` should be restored to their previous values to prevent the UBI layer from reporting 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: -- 2.34.3