[PATCH 19/21] mtd: Nand: Use dev_add_param_bool for erasebad parameter

Sascha Hauer s.hauer at pengutronix.de
Sun Apr 7 10:00:53 EDT 2013


Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mtd/nand/nand_base.c | 22 ++++++++++++----------
 include/linux/mtd/mtd.h      |  1 +
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index fa10d95..67e913a 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -1672,18 +1672,20 @@ EXPORT_SYMBOL(nand_scan_ident);
 EXPORT_SYMBOL(nand_scan_tail);
 EXPORT_SYMBOL(nand_release);
 
-static int mtd_set_erasebad(struct device_d *dev, struct param_d *param,
-		const char *val)
+static int mtd_set_erasebad(struct param_d *param, void *priv)
 {
-	struct mtd_info *mtd = container_of(dev, struct mtd_info, class_dev);
-	int erasebad;
+	struct mtd_info *mtd = priv;
 
-	erasebad = simple_strtoul(val, NULL, 0);
+	if (!mtd->p_allow_erasebad) {
+		mtd->allow_erasebad = false;
+		return 0;
+	}
 
-	if (erasebad && !mtd->allow_erasebad)
-		dev_warn(dev, "Allowing to erase bad blocks. This may be dangerous!\n");
+	if (!mtd->allow_erasebad)
+		dev_warn(&mtd->class_dev,
+			"Allowing to erase bad blocks. This may be dangerous!\n");
 
-	mtd->allow_erasebad = erasebad ? true : false;
+	mtd->allow_erasebad = true;
 
 	return 0;
 }
@@ -1714,8 +1716,8 @@ int add_mtd_nand_device(struct mtd_info *mtd, char *devname)
 		return ret;
 
 	if (IS_ENABLED(CONFIG_NAND_ALLOW_ERASE_BAD))
-		dev_add_param(&mtd->class_dev, "erasebad", mtd_set_erasebad,
-				NULL, 0);
+		dev_add_param_bool(&mtd->class_dev, "erasebad", mtd_set_erasebad,
+			NULL, &mtd->p_allow_erasebad, mtd);
 
 	dev_add_param(&mtd->class_dev, "bbt", NULL, mtd_get_bbt_type, 0);
 
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 390f4b0..df04030 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -208,6 +208,7 @@ struct mtd_info {
 
 	/* If true erasing bad blocks is allowed, this is set via a device parameter */
 	bool allow_erasebad;
+	int p_allow_erasebad;
 };
 
 int mtd_erase(struct mtd_info *mtd, struct erase_info *instr);
-- 
1.8.2.rc2




More information about the barebox mailing list