[PATCH v3 0/6] UBI: add max_beb_per1024 parameter / ioctl

Artem Bityutskiy dedekind1 at gmail.com
Thu Aug 23 08:30:30 EDT 2012


From fa7595564e95672ab87d4a910c6bc02123b75e88 Mon Sep 17 00:00:00 2001
From: Artem Bityutskiy <artem.bityutskiy at linux.intel.com>
Date: Thu, 23 Aug 2012 13:01:11 +0300
Subject: [PATCH] UBI: disallow max_beb_per1024 on NOR flash

If the flash does not admit of bad blocks (e.g., NOR) - disallow using
'max_beb_per1024'.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy at linux.intel.com>
---

Second attempt, did not test :-)

 drivers/mtd/ubi/build.c |   18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 355756b..aaf7df3 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -646,8 +646,18 @@ static int io_init(struct ubi_device *ubi, int max_beb_per1024)
 	ubi->flash_size = ubi->mtd->size;
 
 	if (mtd_can_have_bb(ubi->mtd)) {
-		ubi->bad_allowed = 1;
+		if (max_beb_per1024 < 0 ||
+		    max_beb_per1024 > MAX_MTD_UBI_BEB_LIMIT)
+			return -EINVAL;
+		if (!max_beb_per1024)
+			max_beb_per1024 = CONFIG_MTD_UBI_BEB_LIMIT;
+
 		ubi->bad_peb_limit = get_bad_peb_limit(ubi, max_beb_per1024);
+		ubi->bad_allowed = 1;
+	} else if (max_beb_per1024) {
+		ubi_err("mtd%d does not admit of bad blocks, max_beb_per1024 "
+			"cannot be used", mtd->index);
+		return -EINVAL;
 	}
 
 	if (ubi->mtd->type == MTD_NORFLASH) {
@@ -857,12 +867,6 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
 	struct ubi_device *ubi;
 	int i, err, ref = 0;
 
-	if (max_beb_per1024 < 0 || max_beb_per1024 > MAX_MTD_UBI_BEB_LIMIT)
-		return -EINVAL;
-
-	if (!max_beb_per1024)
-		max_beb_per1024 = CONFIG_MTD_UBI_BEB_LIMIT;
-
 	/*
 	 * Check if we already have the same MTD device attached.
 	 *
-- 
1.7.10.4

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/linux-mtd/attachments/20120823/ac3a44e1/attachment.sig>


More information about the linux-mtd mailing list