Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp907380pxb; Wed, 6 Apr 2022 03:57:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGi29kUuPQARWwlONGh6gSggLbOZL4F3hzjBnZnRS3sj3EC2JMTR/vao9/QuDe+AyWY1cd X-Received: by 2002:a63:dd54:0:b0:382:2fb1:13cf with SMTP id g20-20020a63dd54000000b003822fb113cfmr6478791pgj.72.1649242670285; Wed, 06 Apr 2022 03:57:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649242670; cv=none; d=google.com; s=arc-20160816; b=IsnThMNg6w6c6YCOGif3cWH7aj9yGKds8Am8g+kCq8inKYxV8c6hrINGuDdMG8QM6M Y2qkg0KoRrry2d9P1KWdcZEl6ySUds8tIZ3slnGCGkuQNXBb0O7UULLy/cmc55jKDga4 LzpUVYFqQu63H8+xouG3WH8+2+SPvBxFL5FwE1xAyrGcL+MKMHFhAiOuMXACPBX0Ns0i cavlavyWKcaqOFho3iYdC+U1wDPTidJjPXSKEtWpuyRJcXeKsfBkNILS8LRF6XnJi9pO jli4Nw4eNglorsc0FLA8dnpH7boh3OPTkiGwQ0H48Ot9jDFs8e6T103ulSJUPwtwew3B gy9Q== 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=6rPkePVSeMgQyqilmerpp3mDw184H50E9xBBOmiaBhY=; b=qwewWIeS9I2+IZMBppDjqtNmgGIRsQn66Q8DecHScshD+M2Dq+Iz0O6YXaJNMJE9Ck V9VGvF/7YJvXsoJ/tCrnMcZf64Sx27hwkkDGvO4PJHHT11hxD6JQ+9fxRJsbFBLMrxrb 37clk/qOAxZgveIK9uZ9wZCImogGIiu8R9Jm2mlxJvgSr3Jq4DvkOGTDoKNQypyHWKDo PJKfJbKjU2XrGbsw0kIk4wGdyoM2S6jgsKM8RkGuhWkRDI55wZQIU3rw51QU+/qBI/fy AEUkiRbuS+C4hXhMTBELu7Lv9PvgqYvhbrLGEsAp3LjdaMHy9/ewkqO8O12Xn+FqiRrs 1BfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Qp24ABv/"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id 6-20020a631946000000b00398db2165basi13431103pgz.329.2022.04.06.03.57.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 03:57:50 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Qp24ABv/"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 610361B72ED; Wed, 6 Apr 2022 02:16:14 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352744AbiDEVY2 (ORCPT + 99 others); Tue, 5 Apr 2022 17:24:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354213AbiDEKMT (ORCPT ); Tue, 5 Apr 2022 06:12:19 -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 1C771580F3; Tue, 5 Apr 2022 02:59:04 -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 C8239B817D3; Tue, 5 Apr 2022 09:59:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42BE2C385A1; Tue, 5 Apr 2022 09:59:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649152741; bh=58RmXMaSK5PuvhFzkytvjVsSYIvGzU7PtUDOIzpbiJs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qp24ABv/CoyK+Ixdk2/s30wW/tyeSJZy3yhntrBdpNRewBA0uhW5pd/SFgtdbnXvi NE9qrGYYuwqD9uM4NLLh5GTIC5YU5u1xoM9teSph0pBg9TVDJx1m8u98HrbTLzCKUv XhpU5Sx1wDXZ4ABG/ZUStFDWzaw6l2aTut5L2MY0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhihao Cheng , Richard Weinberger Subject: [PATCH 5.15 886/913] ubi: fastmap: Return error code if memory allocation fails in add_aeb() Date: Tue, 5 Apr 2022 09:32:28 +0200 Message-Id: <20220405070406.379050864@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@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 @@ -468,7 +468,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); @@ -638,8 +640,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 */ @@ -649,8 +653,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 */ @@ -660,8 +666,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 */ @@ -671,8 +679,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);