Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5194454ybv; Tue, 11 Feb 2020 10:58:16 -0800 (PST) X-Google-Smtp-Source: APXvYqyPFV26Y+dTr8RhgM5F7WHE8/wn47MkcNfr124RnOW0HjifhbCq4s575g205qH92S++VSjU X-Received: by 2002:a05:6830:1e37:: with SMTP id t23mr6417817otr.16.1581447496260; Tue, 11 Feb 2020 10:58:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581447496; cv=none; d=google.com; s=arc-20160816; b=t1cw3DPoM0usq8flmsBVjfn/gLXnpdm+961BqeVQPj2RkX/9fMmJCt8gUix7XPNaBD b/H8OCTDs2xvt4Xi4f7Oy3Pg+Q2c7rI6sCZkN69E/UbuSbF/N5XCcUOfmkqhePbnaMWZ S7PH1siJ1+GjeIk0GEpw1rJVvv5NqHvmESVqCz5V4eq0RelZl3wSYQhq+38VipSeqj1z U5fe9cGcRhmV3ibybLkqsq3YUEM/clS4lyqjwDsbKEYm2hNqdo3B4gfzcr9R/7d6QlYN cQiiMqbsW7HUeV/6qrexiFv2li6VZrZ6MHtqi+/ghwRDcQkzCF6lIi5hOLBhjWUQ0Fut 8H3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=ASJsbtRmpkgfovgOvhA84Qty6mtmp7RurFQAFWO1Dxs=; b=C0WCAYEi0f572S1wonJYKRulI0az9er2SDeA+HMSHYO58Eg/8S4mSprZ4p7p5vO+U2 AoVUEs+90k0qaGWD/vEJlZO4ePOB9rthrcgxWrg+yspwITpLNbdsaHR7HRSZyKj3m+Fv HgQHmOtlW7emp9yT0VeGqLqI3rJt5YZ3EAMhxBHu7PaaSEkMSBGVZEhkLL3pPjQf0pUS DT06EiSqVS+RQGnx6qRP4RY9Fs3yew35dTs4+v5kJ0okL4wvZotDOXo6FG+maxEUxr8z f2y4KZSKE9yzOIbANuXowgSwkUc30bqAeAyW+9BPLcfHLIdGJqIBn6FwU0UyesrE99j8 V8nA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i9si2351895otp.139.2020.02.11.10.58.03; Tue, 11 Feb 2020 10:58:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730891AbgBKQf4 convert rfc822-to-8bit (ORCPT + 99 others); Tue, 11 Feb 2020 11:35:56 -0500 Received: from skedge04.snt-world.com ([91.208.41.69]:35438 "EHLO skedge04.snt-world.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728295AbgBKQf4 (ORCPT ); Tue, 11 Feb 2020 11:35:56 -0500 Received: from sntmail14r.snt-is.com (unknown [10.203.32.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by skedge04.snt-world.com (Postfix) with ESMTPS id 384DA67A894; Tue, 11 Feb 2020 17:35:54 +0100 (CET) Received: from sntmail12r.snt-is.com (10.203.32.182) by sntmail14r.snt-is.com (10.203.32.184) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1913.5; Tue, 11 Feb 2020 17:35:53 +0100 Received: from sntmail12r.snt-is.com ([fe80::e551:8750:7bba:3305]) by sntmail12r.snt-is.com ([fe80::e551:8750:7bba:3305%3]) with mapi id 15.01.1913.005; Tue, 11 Feb 2020 17:35:53 +0100 From: Schrempf Frieder To: Boris Brezillon , Schrempf Frieder , Jeff Kletsky , liaoweixiong , Miquel Raynal , Peter Pan CC: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-mtd@lists.infradead.org" , "Richard Weinberger" Subject: [PATCH 3/3] mtd: spinand: Wait for the erase op to finish before writing a bad block marker Thread-Topic: [PATCH 3/3] mtd: spinand: Wait for the erase op to finish before writing a bad block marker Thread-Index: AQHV4PlTblnHiLQcV0asTsn4OWAZ0A== Date: Tue, 11 Feb 2020 16:35:53 +0000 Message-ID: <20200211163452.25442-4-frieder.schrempf@kontron.de> References: <20200211163452.25442-1-frieder.schrempf@kontron.de> In-Reply-To: <20200211163452.25442-1-frieder.schrempf@kontron.de> Accept-Language: de-DE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.17.1 x-originating-ip: [172.25.9.193] x-c2processedorg: 51b406b7-48a2-4d03-b652-521f56ac89f3 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-SnT-MailScanner-Information: Please contact the ISP for more information X-SnT-MailScanner-ID: 384DA67A894.AE793 X-SnT-MailScanner: Not scanned: please contact your Internet E-Mail Service Provider for details X-SnT-MailScanner-SpamCheck: X-SnT-MailScanner-From: frieder.schrempf@kontron.de X-SnT-MailScanner-To: bbrezillon@kernel.org, git-commits@allycomm.com, liaoweixiong@allwinnertech.com, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, miquel.raynal@bootlin.com, peterpandong@micron.com, richard@nod.at, stable@vger.kernel.org X-Spam-Status: No Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Frieder Schrempf Currently when marking a block, we use spinand_erase_op() to erase the block before writing the marker to the OOB area without waiting for the operation to succeed. This can lead to the marking failing silently and no bad block marker being written to the flash. To fix this we reuse the spinand_erase() function, that already does everything we need to do before actually writing the marker. Fixes: 7529df465248 ("mtd: nand: Add core infrastructure to support SPI NANDs") Cc: stable@vger.kernel.org Signed-off-by: Frieder Schrempf --- drivers/mtd/nand/spi/core.c | 56 ++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c index 925db6269861..8a69d13639e2 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -600,6 +600,32 @@ static int spinand_mtd_block_isbad(struct mtd_info *mtd, loff_t offs) return ret; } +static int __spinand_erase(struct nand_device *nand, const struct nand_pos *pos, + bool hard_fail) +{ + struct spinand_device *spinand = nand_to_spinand(nand); + u8 status; + int ret; + + ret = spinand_select_target(spinand, pos->target); + if (ret) + return ret; + + ret = spinand_write_enable_op(spinand); + if (ret) + return ret; + + ret = spinand_erase_op(spinand, pos); + if (ret && hard_fail) + return ret; + + ret = spinand_wait(spinand, &status); + if (!ret && (status & STATUS_ERASE_FAILED)) + ret = -EIO; + + return ret; +} + static int spinand_markbad(struct nand_device *nand, const struct nand_pos *pos) { struct spinand_device *spinand = nand_to_spinand(nand); @@ -614,16 +640,10 @@ static int spinand_markbad(struct nand_device *nand, const struct nand_pos *pos) int ret; /* Erase block before marking it bad. */ - ret = spinand_select_target(spinand, pos->target); - if (ret) - return ret; - - ret = spinand_write_enable_op(spinand); + ret = __spinand_erase(nand, pos, false); if (ret) return ret; - spinand_erase_op(spinand, pos); - return spinand_write_page(spinand, &req); } @@ -644,27 +664,7 @@ static int spinand_mtd_block_markbad(struct mtd_info *mtd, loff_t offs) static int spinand_erase(struct nand_device *nand, const struct nand_pos *pos) { - struct spinand_device *spinand = nand_to_spinand(nand); - u8 status; - int ret; - - ret = spinand_select_target(spinand, pos->target); - if (ret) - return ret; - - ret = spinand_write_enable_op(spinand); - if (ret) - return ret; - - ret = spinand_erase_op(spinand, pos); - if (ret) - return ret; - - ret = spinand_wait(spinand, &status); - if (!ret && (status & STATUS_ERASE_FAILED)) - ret = -EIO; - - return ret; + return __spinand_erase(nand, pos, true); } static int spinand_mtd_erase(struct mtd_info *mtd, -- 2.17.1