Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp43962lfe; Fri, 15 Apr 2022 18:36:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZD3Bn2hXwE2shwkTHT5mWTuOHLzTKr0ogJxvH0GfRbyeQa33VsiaU6Bd89NObkFabom0b X-Received: by 2002:a17:902:dac5:b0:158:5db6:3503 with SMTP id q5-20020a170902dac500b001585db63503mr1641960plx.76.1650072975277; Fri, 15 Apr 2022 18:36:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650072975; cv=none; d=google.com; s=arc-20160816; b=Z0XQZCgEDsX+HrWc9mjpAZ26kNm9YRD2dseptHKV+UVTQAuEwN7cyipTAhJL3y6whc U69AAW1N/pv+wnTgnQVB+x9D+BJz3+71eBd9ig/o3Bj5nWLZXIbLcPpE+x/EN3HhoTFd ARe77zW256JyACP+6ExgJzgTTF0s4QXJr3Egfi3RZOFkwZ/1tu5gXrEbpEONMHYV9Sgs cDOyB4bG3U/PI5CR8Ow7PtBZQNKMZcnd2c24/Vv5ky8QnDki+A273WU85yo1TT0GZf+p cN6DO1xPafWbCUHJs87w7XdvaIvcciLOGRMLTHhe6BdiM0kau23RQe1TTyx6RrLRy8SY YLDw== 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=JxzfOZ2PIuHLWA2322S0KwSyTZ3YofZZEvRwReYVduY=; b=hK5ilvBwRbSiVkMJg2Bg6f6yYFQqivf1hWpDyey9mf/Cqwo2In99vzyiji0aGBFoKB TzNizAj5C7QJAHsDMmYSsVLK2rX6RmDrbObim7CcLHw3D/FKB5rJ7/De2SHnxDOud95o oftVp924dlU8akUfuux92c1QXboQ61uJaYBpI4AOxHMuWcS8VE3ekjM6OwdW9+w/ap4m /ilYNQuqXPwGUmdOrhn9+CjkUeOlf4Ev9tSZKZubnQTQkRkhdq8s3GIQkRFxkO484jgG /R6lKyi5RcE54EvU6vLDX12090oKQlDjukDlpyxyxKDqs0EJls19BgU+DB30KN1Ts3/J 6hvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=po2maBx7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id h6-20020a056a00230600b004fac017a5b1si3104445pfh.95.2022.04.15.18.36.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 18:36:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=po2maBx7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 01C1B15D3AF; Fri, 15 Apr 2022 18:02:34 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245039AbiDNOHa (ORCPT + 99 others); Thu, 14 Apr 2022 10:07:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344000AbiDNNaN (ORCPT ); Thu, 14 Apr 2022 09:30:13 -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 2BC51986EC; Thu, 14 Apr 2022 06:25:54 -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 DC300B82984; Thu, 14 Apr 2022 13:25:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 509C9C385A5; Thu, 14 Apr 2022 13:25:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649942751; bh=7RxymfT8Xm1svcbf3FJpx9qjtzeoBy5JDrZwS/fzW4I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=po2maBx7r6F6TX5P7olzOE6pJq21DQV8xBct+O4IK40ABO6SrZ4kmvfZvDf8P5ozr uBYvqL6wjKmsffWHlpUPFQ99jjjT94OI8vY+dwWnAceKgPZiFJQ2980o6QQG3ip81a X3sG5ipsS1e2dHZsTL8TKi14bvgUFW4Bu0tjCvE0= 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.19 249/338] ubi: fastmap: Return error code if memory allocation fails in add_aeb() Date: Thu, 14 Apr 2022 15:12:32 +0200 Message-Id: <20220414110845.979154628@linuxfoundation.org> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20220414110838.883074566@linuxfoundation.org> References: <20220414110838.883074566@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 @@ -477,7 +477,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); @@ -647,8 +649,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 */ @@ -658,8 +662,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 */ @@ -669,8 +675,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 */ @@ -680,8 +688,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);