From patchwork Mon Feb 19 23:22:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 875339 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="UpgrWg83"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zlftH45Tbz9s01 for ; Tue, 20 Feb 2018 10:22:43 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=a+qNV/Bkgd06tHt6n7TsFxCIpC7KYcOhyZEiL8KPSnI=; b=Upg rWg831/iS2Pu77lJ2KizofitI6fNZVVqTkVrHopqJjprHPjJ7Xtry17p7iMxyfJG4STU9C+guR5Qm rACUeryA3HuXQ+w7nc4uaNOZ99m4qhiHIWRsJuOQK3vEfuJ/agmRVbCHCVejyzsFGAFd/gN6ZsHaX lHdbl+WXzTeN2O5iwCHGVmZm+XtB5EJoInqfF9yHM8dEkYswgCi8w0wIcMxwsBEcTJtOARUvxu7oY NYxgTsL2JHrDU0Q2LnQ9UExRqK5yGD9Q0rc3LgtaxEKxoD8vH/hO0WZsandvP5nZMMZ3oQfTqkiJS DgZyPWH6V9HvxUN2woQKMF0GXsjwIKA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1enulW-0005w0-Mh; Mon, 19 Feb 2018 23:22:34 +0000 Received: from mail.free-electrons.com ([62.4.15.54]) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1enulS-0005uP-4r for linux-mtd@lists.infradead.org; Mon, 19 Feb 2018 23:22:32 +0000 Received: by mail.free-electrons.com (Postfix, from userid 110) id 0976A20715; Tue, 20 Feb 2018 00:22:18 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost.localdomain (unknown [91.224.148.103]) by mail.free-electrons.com (Postfix) with ESMTPSA id 7B0D8203B5; Tue, 20 Feb 2018 00:22:17 +0100 (CET) From: Miquel Raynal To: Boris Brezillon , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , Cyrille Pitchen Subject: [PATCH v2] mtd: nftl/inftl: check mtd_erase() return value Date: Tue, 20 Feb 2018 00:22:15 +0100 Message-Id: <20180219232215.15938-1-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.14.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180219_152230_351883_E94F8C46 X-CRM114-Status: GOOD ( 12.15 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mtd@lists.infradead.org, Miquel Raynal MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Since the creation of mtd_erase(), the function can return a negative error code without updating the instr->state flag. This happens for instance when ->_erase() is not implemented or ->erasesize has an invalid value. The calling function should error out in this case. Functions in nftlmount/inftlmount call mtd_erase() without checking the return code. The instr->state flag is checked but might not have been updated depending on the error path. Add checks on the returned value of mtd_erase(). Signed-off-by: Miquel Raynal --- Changes since v1: - Fix disgraceful compilation issue. drivers/mtd/inftlmount.c | 7 +++++-- drivers/mtd/nftlmount.c | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/inftlmount.c b/drivers/mtd/inftlmount.c index 8d6bb189ea8e..34fd6180966a 100644 --- a/drivers/mtd/inftlmount.c +++ b/drivers/mtd/inftlmount.c @@ -219,7 +219,9 @@ static int find_boot_record(struct INFTLrecord *inftl) */ instr->addr = ip->Reserved0 * inftl->EraseSize; instr->len = inftl->EraseSize; - mtd_erase(mtd, instr); + ret = mtd_erase(mtd, instr); + if (ret < 0) + return ret; } if ((ip->lastUnit - ip->firstUnit + 1) < ip->virtualUnits) { printk(KERN_WARNING "INFTL: Media Header " @@ -393,7 +395,8 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block) mark only the failed block in the bbt. */ for (physblock = 0; physblock < inftl->EraseSize; physblock += instr->len, instr->addr += instr->len) { - mtd_erase(inftl->mbd.mtd, instr); + if (mtd_erase(inftl->mbd.mtd, instr) < 0) + goto fail; if (instr->state == MTD_ERASE_FAILED) { printk(KERN_WARNING "INFTL: error while formatting block %d\n", diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c index 184c8fbfe465..8dbc40ab7d73 100644 --- a/drivers/mtd/nftlmount.c +++ b/drivers/mtd/nftlmount.c @@ -331,7 +331,8 @@ int NFTL_formatblock(struct NFTLrecord *nftl, int block) instr->mtd = nftl->mbd.mtd; instr->addr = block * nftl->EraseSize; instr->len = nftl->EraseSize; - mtd_erase(mtd, instr); + if (mtd_erase(mtd, instr) < 0) + goto fail; if (instr->state == MTD_ERASE_FAILED) { printk("Error while formatting block %d\n", block);