Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp701140pxb; Tue, 5 Apr 2022 19:23:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKlfTNJm9+6L6uRkot25OMI3FC4RyS9tJY8JOYb2C2e7Hsc1vwm1doS/YD3Aj/aOIv5isB X-Received: by 2002:a17:902:8684:b0:154:af35:82ce with SMTP id g4-20020a170902868400b00154af3582cemr6427726plo.137.1649211797429; Tue, 05 Apr 2022 19:23:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649211797; cv=none; d=google.com; s=arc-20160816; b=W2Z5eEr6xD0yd+1TzBIY8Ny4qGRPElDyPKe+eRWzN/UY3inimFoIM0948R9OBhjZ+I /mQ/pCBcp/5ziikjwfymWQhYYrMPJPSRnec2Mwkk5MyhAqReMbvNvQ6eMUoJTyWy25/v Gsh2Yr4LuzxB4unU/BSWmVFU1AxXqD13Vs13Y0wyhXpANH/9G3iYw8EupROi5I2BEQjz jTlh6iuFNUonat18p43SOzIo4BK4eOaMpgdgf0ToJTa0uI5tnk06kAHjZCc9TzXXHBNP KCk8KzRcB5siYYg68IRL9Ow30bRU5EYA9MYlyzGDNaNiG0GyaosZRBi8/okJo/wRy0zv z9rw== 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=CKbhkoZ9yVlXoY6FhOot7msL0Q0Vrn/IIt1woxBKdOvtaCFoRE1o2ek6vbIP8zdzS9 VEWC1IRAEgbOEuah/DfKtP8YXx+n7s6aT8gzGbXudH9ptPn207ByPWM8y23NCzq6RT46 IYVqkIXJYKNGJ1uzKnQjUi87e8Xr9mNHngNnmaHw9JHWKHHUvo3dGjhxZAscw2RJrloe TowKgZQ/glavdgTLxc521ow5R3sEKs4QA5ZSA8yxnYkNBIQmCAawHB25Z0B2GNakwTHw 5o3curRpunVuano6fimyRZ3KbLrKy27l32iCH/Um0aQixtHqs1laJZr5NnohNxv9l0FO Ag2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ffyRImDJ; 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 n2-20020a170902e54200b00156d87887eesi2668107plf.83.2022.04.05.19.23.02; Tue, 05 Apr 2022 19:23:17 -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=ffyRImDJ; 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 S245439AbiDEOAX (ORCPT + 99 others); Tue, 5 Apr 2022 10:00:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237382AbiDEJ3Q (ORCPT ); Tue, 5 Apr 2022 05:29:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C647E29D6; Tue, 5 Apr 2022 02:16:45 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 9B6DE615E4; Tue, 5 Apr 2022 09:16:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9BE0C385A0; Tue, 5 Apr 2022 09:16:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649150204; bh=58RmXMaSK5PuvhFzkytvjVsSYIvGzU7PtUDOIzpbiJs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ffyRImDJN5h8IJ2CCHDY9JaYcZe917LAazHIDPkAjcKFfenJDWn+rMa3TKFIAteyd GfLCTp396vEitMJ1OciChRbDEFygvQZPL70kLuwcO6GGQFFDkF4Cuth1L56sFQbjvZ VA74XstYzpwBNJzE5RJq+GRiInmC276RCOTRgfto= 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.16 0990/1017] ubi: fastmap: Return error code if memory allocation fails in add_aeb() Date: Tue, 5 Apr 2022 09:31:43 +0200 Message-Id: <20220405070423.588834231@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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.1 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 @@ -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);