public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Brian Norris <computersforpeace@gmail.com>
To: Boris Brezillon <boris.brezillon@free-electrons.com>
Cc: Mark Rutland <mark.rutland@arm.com>,
	devicetree@vger.kernel.org, Pawel Moll <pawel.moll@arm.com>,
	Ian Campbell <ijc+devicetree@hellion.org.uk>,
	linux-kernel@vger.kernel.org,
	Yassin Jaffer <yassinjaffer@gmail.com>,
	linux-sunxi@googlegroups.com, Rob Herring <robh+dt@kernel.org>,
	linux-mtd@lists.infradead.org, Kumar Gala <galak@codeaurora.org>,
	David Woodhouse <dwmw2@infradead.org>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v7 1/2] mtd: nand: add sunxi NAND flash controller support
Date: Tue, 28 Oct 2014 11:13:11 -0700	[thread overview]
Message-ID: <20141028181310.GA23619@ld-irv-0074> (raw)
In-Reply-To: <1413896922-11680-2-git-send-email-boris.brezillon@free-electrons.com>

Hi Boris,

On Tue, Oct 21, 2014 at 03:08:41PM +0200, Boris Brezillon wrote:
> +static int sunxi_nand_hw_ecc_ctrl_init(struct mtd_info *mtd,
> +				       struct nand_ecc_ctrl *ecc,
> +				       struct device_node *np)
> +{
> +	struct nand_ecclayout *layout;
> +	int i, j;
> +	int ret;
> +
> +	ret = sunxi_nand_hw_common_ecc_ctrl_init(mtd, ecc, np);
> +	if (ret)
> +		return ret;
> +
> +	ecc->read_page = sunxi_nfc_hw_ecc_read_page;
> +	ecc->write_page = sunxi_nfc_hw_ecc_write_page;
> +	layout = ecc->layout;
> +
> +	for (i = 0; i < ecc->steps; i++) {

Hmm, did you retest this since changing this to ecc->steps? I think this
won't work, since ecc->steps is only initialized in nand_scan_tail(),
which comes after this. I only recommended the change for the
{read,write}_page() type of functions, not the initialization functions.

[snip the rest]

So I'd suggest the following additional patch, and otherwise, the series
is fine with me. If you give your ack, I can just squash this in and
apply it to my tree:

diff --git a/drivers/mtd/nand/sunxi_nand.c b/drivers/mtd/nand/sunxi_nand.c
index ea615dc442a4..ccaa8e283388 100644
--- a/drivers/mtd/nand/sunxi_nand.c
+++ b/drivers/mtd/nand/sunxi_nand.c
@@ -931,6 +931,7 @@ static int sunxi_nand_hw_common_ecc_ctrl_init(struct mtd_info *mtd,
 	struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller);
 	struct sunxi_nand_hw_ecc *data;
 	struct nand_ecclayout *layout;
+	int nsectors;
 	int ret;
 	int i;
 
@@ -959,13 +960,14 @@ static int sunxi_nand_hw_common_ecc_ctrl_init(struct mtd_info *mtd,
 	ecc->bytes = ALIGN(ecc->bytes, 2);
 
 	layout = &data->layout;
+	nsectors = mtd->writesize / ecc->size;
 
-	if (mtd->oobsize < ((ecc->bytes + 4) * ecc->steps)) {
+	if (mtd->oobsize < ((ecc->bytes + 4) * nsectors)) {
 		ret = -EINVAL;
 		goto err;
 	}
 
-	layout->eccbytes = (ecc->bytes * ecc->steps);
+	layout->eccbytes = (ecc->bytes * nsectors);
 
 	ecc->layout = layout;
 	ecc->priv = data;
@@ -988,6 +990,7 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct mtd_info *mtd,
 				       struct device_node *np)
 {
 	struct nand_ecclayout *layout;
+	int nsectors;
 	int i, j;
 	int ret;
 
@@ -998,8 +1001,9 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct mtd_info *mtd,
 	ecc->read_page = sunxi_nfc_hw_ecc_read_page;
 	ecc->write_page = sunxi_nfc_hw_ecc_write_page;
 	layout = ecc->layout;
+	nsectors = mtd->writesize / ecc->size;
 
-	for (i = 0; i < ecc->steps; i++) {
+	for (i = 0; i < nsectors; i++) {
 		if (i) {
 			layout->oobfree[i].offset =
 				layout->oobfree[i - 1].offset +
@@ -1022,13 +1026,13 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct mtd_info *mtd,
 					layout->oobfree[i].length + j;
 	}
 
-	if (mtd->oobsize > (ecc->bytes + 4) * ecc->steps) {
-		layout->oobfree[ecc->steps].offset =
-				layout->oobfree[ecc->steps - 1].offset +
-				layout->oobfree[ecc->steps - 1].length +
+	if (mtd->oobsize > (ecc->bytes + 4) * nsectors) {
+		layout->oobfree[nsectors].offset =
+				layout->oobfree[nsectors - 1].offset +
+				layout->oobfree[nsectors - 1].length +
 				ecc->bytes;
-		layout->oobfree[ecc->steps].length = mtd->oobsize -
-				((ecc->bytes + 4) * ecc->steps);
+		layout->oobfree[nsectors].length = mtd->oobsize -
+				((ecc->bytes + 4) * nsectors);
 	}
 
 	return 0;
@@ -1039,6 +1043,7 @@ static int sunxi_nand_hw_syndrome_ecc_ctrl_init(struct mtd_info *mtd,
 						struct device_node *np)
 {
 	struct nand_ecclayout *layout;
+	int nsectors;
 	int i;
 	int ret;
 
@@ -1051,8 +1056,9 @@ static int sunxi_nand_hw_syndrome_ecc_ctrl_init(struct mtd_info *mtd,
 	ecc->write_page = sunxi_nfc_hw_syndrome_ecc_write_page;
 
 	layout = ecc->layout;
+	nsectors = mtd->writesize / ecc->size;
 
-	for (i = 0; i < (ecc->bytes * ecc->steps); i++)
+	for (i = 0; i < (ecc->bytes * nsectors); i++)
 		layout->eccpos[i] = i;
 
 	layout->oobfree[0].length = mtd->oobsize - i;

  reply	other threads:[~2014-10-28 18:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-21 13:08 [PATCH v7 0/2] mtd: nand: add sunxi NAND flash controller support Boris Brezillon
2014-10-21 13:08 ` [PATCH v7 1/2] " Boris Brezillon
2014-10-28 18:13   ` Brian Norris [this message]
2014-10-28 20:15     ` Boris Brezillon
2014-10-29 13:02     ` Boris Brezillon
2014-10-29 17:08       ` Brian Norris
2014-10-21 13:08 ` [PATCH v7 2/2] mtd: nand: add sunxi NFC dt bindings doc Boris Brezillon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141028181310.GA23619@ld-irv-0074 \
    --to=computersforpeace@gmail.com \
    --cc=boris.brezillon@free-electrons.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dwmw2@infradead.org \
    --cc=galak@codeaurora.org \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux-sunxi@googlegroups.com \
    --cc=mark.rutland@arm.com \
    --cc=pawel.moll@arm.com \
    --cc=robh+dt@kernel.org \
    --cc=yassinjaffer@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox