Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2885058pxb; Mon, 18 Apr 2022 10:15:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz89freJwa1QqZzzIRUNNK1GOxpnj7jVF39weULBiY8HNbPjyeiE5aBltolCvPjS5SJCFxd X-Received: by 2002:a17:902:7798:b0:158:ee95:f45b with SMTP id o24-20020a170902779800b00158ee95f45bmr9903630pll.97.1650302128696; Mon, 18 Apr 2022 10:15:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650302128; cv=none; d=google.com; s=arc-20160816; b=H5y5K48CopFm1oFXX9UOL9OQD8eFjj60K1BVQgyWmGVDjpwthCx/yXJyqlnUc9UUQK zsA13CT+FwHelJOu8mpNG3AAjPeWF1F+ZMj60xvOtJfQ51Paekj0cnFVkwjTYDpWWTkM 91PSH/eytqkKCFWwyD367ndkCe3SPCDUVKn8nl/H01MJNHg9aqedaQu/+7gqYgcJrQLN QQApkqlqDEbV9ws2Zv0o+K50+MtaIDJNQxRY4JAWhZo10Xmcnr+dx9Hj7JVxq39N5qeX fy2WA6yYmc4hTUaTcfDVthc1DxWZaCBUFe8dYjR+zovaL3ozvmaOdn6gCgYBbccgjlQ0 6I5w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=N1sHjuxFs29xSkM8mGweZqTKnay8Le+Iq39wN8lSp+U=; b=x5eWBnDQuxoW/JWPWKaSVfYPjpvcQjmgfDuB0faWH5VaKoj0uSjXEXOEc4QfEAUNjE QrHd/SI602ONLumurK4sOsZVRzvUpyjV/bfRc7rC367CZV7Hb6DIZGpTipukKMon7e/n 8L/faGW4BNJS1d20ijnbgVe4RP6tns5tU6htmgyelPVawSZEiVWX4u0v2RWW2B0vT4NR VPU8uu3o0F+ph3MiTlRuUbkT1YDBC3zO3Ti/C47gkLHHifXaWXrcCn68MECHElER+i4D avQPg19gPMRkol428QuQmf1hgbFTOTunnGBde/HvsGz2dLOxMfrYnTBziFv4YHMoOMzk ACag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Jc5T2q46; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c8-20020aa78e08000000b004fa8a73c6ecsi8628573pfr.180.2022.04.18.10.15.11; Mon, 18 Apr 2022 10:15:28 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Jc5T2q46; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244529AbiDRN52 (ORCPT + 99 others); Mon, 18 Apr 2022 09:57:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244897AbiDRNbA (ORCPT ); Mon, 18 Apr 2022 09:31:00 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6CC2E51; Mon, 18 Apr 2022 05:57:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A4EF4B80E4B; Mon, 18 Apr 2022 12:57:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E379BC385A7; Mon, 18 Apr 2022 12:57:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650286636; bh=fzk8MKUGqmpclWYl7A30PfvIc3vCf2G+DHGNqab7TAM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jc5T2q46t1Om+WxpvqAXcQith1Hmd7CWLK9/RWS+aUFy5Xxyc2GB8snC4Bw1PGVf/ 9BOSEqJcW8hMavsnl+wxkOMPc4wMtL/CJwHzsUplxgRWJ5cOzio4HUI83z9wg6JuwW XZpoM+qR9dby8Pot1b3o4LLRb6x0IaVm6cDqKAC8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhihao Cheng , Richard Weinberger Subject: [PATCH 4.14 197/284] ubi: fastmap: Return error code if memory allocation fails in add_aeb() Date: Mon, 18 Apr 2022 14:12:58 +0200 Message-Id: <20220418121217.330564674@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121210.689577360@linuxfoundation.org> References: <20220418121210.689577360@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-kernel@vger.kernel.org From: Zhihao Cheng commit c3c07fc25f37c157fde041b3a0c3dfcb1590cbce upstream. Abort fastmap scanning and return error code if memory allocation fails in add_aeb(). Otherwise ubi will get wrong peb statistics information after scanning. Fixes: dbb7d2a88d2a7b ("UBI: Add fastmap core") Signed-off-by: Zhihao Cheng Signed-off-by: Richard Weinberger Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/ubi/fastmap.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) --- a/drivers/mtd/ubi/fastmap.c +++ b/drivers/mtd/ubi/fastmap.c @@ -478,7 +478,9 @@ static int scan_pool(struct ubi_device * if (err == UBI_IO_FF_BITFLIPS) scrub = 1; - add_aeb(ai, free, pnum, ec, scrub); + ret = add_aeb(ai, free, pnum, ec, scrub); + if (ret) + goto out; continue; } else if (err == 0 || err == UBI_IO_BITFLIPS) { dbg_bld("Found non empty PEB:%i in pool", pnum); @@ -648,8 +650,10 @@ static int ubi_attach_fastmap(struct ubi if (fm_pos >= fm_size) goto fail_bad; - add_aeb(ai, &ai->free, be32_to_cpu(fmec->pnum), - be32_to_cpu(fmec->ec), 0); + ret = add_aeb(ai, &ai->free, be32_to_cpu(fmec->pnum), + be32_to_cpu(fmec->ec), 0); + if (ret) + goto fail; } /* read EC values from used list */ @@ -659,8 +663,10 @@ static int ubi_attach_fastmap(struct ubi if (fm_pos >= fm_size) goto fail_bad; - add_aeb(ai, &used, be32_to_cpu(fmec->pnum), - be32_to_cpu(fmec->ec), 0); + ret = add_aeb(ai, &used, be32_to_cpu(fmec->pnum), + be32_to_cpu(fmec->ec), 0); + if (ret) + goto fail; } /* read EC values from scrub list */ @@ -670,8 +676,10 @@ static int ubi_attach_fastmap(struct ubi if (fm_pos >= fm_size) goto fail_bad; - add_aeb(ai, &used, be32_to_cpu(fmec->pnum), - be32_to_cpu(fmec->ec), 1); + ret = add_aeb(ai, &used, be32_to_cpu(fmec->pnum), + be32_to_cpu(fmec->ec), 1); + if (ret) + goto fail; } /* read EC values from erase list */ @@ -681,8 +689,10 @@ static int ubi_attach_fastmap(struct ubi if (fm_pos >= fm_size) goto fail_bad; - add_aeb(ai, &ai->erase, be32_to_cpu(fmec->pnum), - be32_to_cpu(fmec->ec), 1); + ret = add_aeb(ai, &ai->erase, be32_to_cpu(fmec->pnum), + be32_to_cpu(fmec->ec), 1); + if (ret) + goto fail; } ai->mean_ec = div_u64(ai->ec_sum, ai->ec_count);