mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH] mtd: nand: imx-bbm: use raw reading when checking for factory BBM
Date: Thu,  7 Jul 2016 11:48:43 +0200	[thread overview]
Message-ID: <1467884923-24060-1-git-send-email-u.kleine-koenig@pengutronix.de> (raw)

This is necessary to prevent the imx_nand_bbm command to bail out
on ECC errors which leaves the device without BBT.

Also simplify buffer management: Use on-stack buffer instead of malloc.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/mtd/nand/nand_imx_bbm.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/mtd/nand/nand_imx_bbm.c b/drivers/mtd/nand/nand_imx_bbm.c
index 251dfe5d3f12..eb3318c08aa6 100644
--- a/drivers/mtd/nand/nand_imx_bbm.c
+++ b/drivers/mtd/nand/nand_imx_bbm.c
@@ -52,12 +52,20 @@
  * on the flash BBT.
  *
  */
-static int checkbad(struct mtd_info *mtd, loff_t ofs, void *__buf)
+static int checkbad(struct mtd_info *mtd, loff_t ofs)
 {
 	int ret, retlen;
-	uint8_t *buf = __buf;
+	uint8_t buf[mtd->writesize + mtd->oobsize];
+	struct mtd_oob_ops ops;
 
-	ret = mtd->read(mtd, ofs, mtd->writesize, &retlen, buf);
+	ops.mode = MTD_OPS_RAW;
+	ops.ooboffs = 0;
+	ops.datbuf = buf;
+	ops.len = mtd->writesize;
+	ops.oobbuf = buf + mtd->writesize;
+	ops.ooblen = mtd->oobsize;
+
+	ret = mtd_read_oob(mtd, ofs, &ops);
 	if (ret < 0)
 		return ret;
 
@@ -88,18 +96,12 @@ static void *create_bbt(struct mtd_info *mtd)
 	if (!bbt)
 		return ERR_PTR(-ENOMEM);
 
-	buf = malloc(mtd->writesize);
-	if (!buf) {
-		ret = -ENOMEM;
-		goto out2;
-	}
-
 	numblocks = mtd->size >> (chip->bbt_erase_shift - 1);
 
 	for (i = 0; i < numblocks;) {
-		ret = checkbad(mtd, from, buf);
+		ret = checkbad(mtd, from);
 		if (ret < 0)
-			goto out1;
+			goto out;
 
 		if (ret) {
 			bbt[i >> 3] |= 0x03 << (i & 0x6);
@@ -113,9 +115,7 @@ static void *create_bbt(struct mtd_info *mtd)
 
 	return bbt;
 
-out1:
-	free(buf);
-out2:
+out:
 	free(bbt);
 
 	return ERR_PTR(ret);
-- 
2.8.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

                 reply	other threads:[~2016-07-07  9:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1467884923-24060-1-git-send-email-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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