Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4695772ybv; Mon, 17 Feb 2020 04:11:35 -0800 (PST) X-Google-Smtp-Source: APXvYqwCW22zWD4RRsiRPsYIJXIzMzKasHlCay0A0KbQLS5Wrg0yJjPMVRCQVUW5lQsj2mmUROpF X-Received: by 2002:a05:6830:12d5:: with SMTP id a21mr12332480otq.296.1581941495815; Mon, 17 Feb 2020 04:11:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581941495; cv=none; d=google.com; s=arc-20160816; b=SDxw++W87fHr6fIeb5R78H2W6AAfrecnpo1h2KpHOr9itN4p/7b6ou8oxqcMwWHqo3 xE659uHMBpfBayyoP++F4qJnlXYywLWhb9SWOFH4X7PFdGfWbUN3TtcJzfacGkTXkorB i5wYYOyyzpLwcMdFzk74Sf+QKdek2wTmCaZdYfkzr3UgOrr6fgpnAXJDgfW+VdSCRore +FJgVWnivneq743rrPQ+djroBRs6FvDRd5DerBsqyjO/X0h3tchB/zNmA21QNoAOYqD9 oDq0i3Z4/gAfMa0jd/WH75gAzQueIW2qV5elBLWXe4s4B1vhPRQSwUgYu0jk5TmTKuor CXOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=FuGdPyzaY63nZl+YfAeydClt3KTM9Q63sRqbQ3ciab4=; b=LlS1fNLHC/F+DQ8+1eukjHlbsIxlRvnSaYAPWYdm/hrzgNgDQN5DJ7IinCSUR1QRN5 rnuBeaW/bbbImXsPxEFPad4iA+nWsSz0LR2z+I2DOilYRBl35mOdtLQF8SaQDMCy77sK wupzjnCvL4IjObTWiCdND7aiuQAl4kUMRvFUs8lYmkjbE5CrH7kMhX5vKYaG7D7ZocbT kBZTi+wt5+29P10hQzqoyMV5MI/7jt5j9wig3h6+qKE0fzR8QpqMJM810LIdG/AphmPQ z6JaLqrOeJeaCj1njwhHrOQjFn7oSiw1elXqsTqAzaXBTEbGQuE9eKVylw0LI+64MieW 0Zsg== 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 d14si6021501oic.201.2020.02.17.04.11.23; Mon, 17 Feb 2020 04:11:35 -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 S1727277AbgBQKjY convert rfc822-to-8bit (ORCPT + 99 others); Mon, 17 Feb 2020 05:39:24 -0500 Received: from relay11.mail.gandi.net ([217.70.178.231]:51355 "EHLO relay11.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725972AbgBQKjX (ORCPT ); Mon, 17 Feb 2020 05:39:23 -0500 Received: from xps13 (lfbn-tou-1-1151-102.w90-76.abo.wanadoo.fr [90.76.211.102]) (Authenticated sender: miquel.raynal@bootlin.com) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 9E731100019; Mon, 17 Feb 2020 10:39:20 +0000 (UTC) Date: Mon, 17 Feb 2020 11:39:19 +0100 From: Miquel Raynal To: Schrempf Frieder Cc: Boris Brezillon , Jeff Kletsky , liaoweixiong , Peter Pan , "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-mtd@lists.infradead.org" , "Richard Weinberger" Subject: Re: [PATCH 3/3] mtd: spinand: Wait for the erase op to finish before writing a bad block marker Message-ID: <20200217113919.0508acc4@xps13> In-Reply-To: <20200211163452.25442-4-frieder.schrempf@kontron.de> References: <20200211163452.25442-1-frieder.schrempf@kontron.de> <20200211163452.25442-4-frieder.schrempf@kontron.de> Organization: Bootlin X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Frieder, Schrempf Frieder wrote on Tue, 11 Feb 2020 16:35:53 +0000: > 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. > Thanks a lot for this series! Yet I don't really understand the point of waiting for the erasure if it failed: we don't really care as programming (1 -> 0) cells is always possible. Are you sure this lead to an error? Also, why just not calling spinand_erase() instead of spinand_erase_op() from spinand_markbad()? > 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, Thanks, Miquèl