mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 4/6] mtd: refactor bb device creation
Date: Mon, 28 Apr 2014 11:49:37 +0200	[thread overview]
Message-ID: <1398678579-17491-4-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1398678579-17491-1-git-send-email-s.hauer@pengutronix.de>

This refactors the code so that we get a mtd_add_bb which can
be used to create a bb dev on a mtd_info.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mtd/nand/nand-bb.c | 53 +++++++++++++++++++++++++++-------------------
 include/nand.h             |  6 ++++++
 2 files changed, 37 insertions(+), 22 deletions(-)

diff --git a/drivers/mtd/nand/nand-bb.c b/drivers/mtd/nand/nand-bb.c
index 06b5824..0d3de41 100644
--- a/drivers/mtd/nand/nand-bb.c
+++ b/drivers/mtd/nand/nand-bb.c
@@ -29,6 +29,7 @@
 #include <fcntl.h>
 #include <libgen.h>
 #include <linux/list.h>
+#include <linux/err.h>
 
 struct nand_bb {
 	char *name;
@@ -240,32 +241,18 @@ static struct file_operations nand_bb_ops = {
 
 static LIST_HEAD(bb_list);
 
-/**
- * Add a bad block aware device ontop of another (NAND) device
- * @param[in] dev The device to add a partition on
- * @param[in] name Partition name (can be obtained with devinfo command)
- * @return The device representing the new partition.
- */
-int dev_add_bb_dev(const char *path, const char *name)
+struct cdev *mtd_add_bb(struct mtd_info *mtd, const char *name)
 {
 	struct nand_bb *bb;
-	struct cdev *parent;
-	int ret = -ENOMEM;
-
-	parent = cdev_by_name(path);
-	if (!parent)
-		return -ENODEV;
-
-	if (!parent->mtd)
-		return -EINVAL;
+	int ret;
 
 	bb = xzalloc(sizeof(*bb));
-	bb->mtd = parent->mtd;
+	bb->mtd = mtd;
 
 	if (name)
 		bb->cdev.name = xstrdup(name);
 	else
-		bb->cdev.name = asprintf("%s.bb", path);;
+		bb->cdev.name = asprintf("%s.bb", mtd->cdev.name);
 
 	nand_bb_calc_size(bb);
 	bb->cdev.ops = &nand_bb_ops;
@@ -273,15 +260,37 @@ int dev_add_bb_dev(const char *path, const char *name)
 
 	ret = devfs_create(&bb->cdev);
 	if (ret)
-		goto out4;
+		goto err;
 
 	list_add_tail(&bb->list, &bb_list);
 
-	return 0;
+	return &bb->cdev;
 
-out4:
+err:
 	free(bb);
-	return ret;
+	return ERR_PTR(ret);
+}
+
+/**
+ * Add a bad block aware device ontop of another (NAND) device
+ * @param[in] dev The device to add a partition on
+ * @param[in] name Partition name (can be obtained with devinfo command)
+ * @return The device representing the new partition.
+ */
+int dev_add_bb_dev(const char *path, const char *name)
+{
+	struct cdev *parent, *cdev;
+
+	parent = cdev_by_name(path);
+	if (!parent)
+		return -ENODEV;
+
+	if (!parent->mtd)
+		return -EINVAL;
+
+	cdev = mtd_add_bb(parent->mtd, name);
+
+	return PTR_ERR(cdev);
 }
 
 int dev_remove_bb_dev(const char *name)
diff --git a/include/nand.h b/include/nand.h
index a0e77cc..1da35d0 100644
--- a/include/nand.h
+++ b/include/nand.h
@@ -7,6 +7,7 @@ struct nand_bb;
 #ifdef CONFIG_NAND
 int dev_add_bb_dev(const char *filename, const char *name);
 int dev_remove_bb_dev(const char *name);
+struct cdev *mtd_add_bb(struct mtd_info *mtd, const char *name);
 #else
 static inline int dev_add_bb_dev(const char *filename, const char *name) {
 	return 0;
@@ -15,6 +16,11 @@ static inline int dev_remove_bb_dev(const char *name)
 {
 	return 0;
 }
+
+static inline struct cdev *mtd_add_bb(struct mtd_info *mtd, const char *name)
+{
+	return NULL;
+}
 #endif
 
 #endif /* __NAND_H__ */
-- 
1.9.1


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

  parent reply	other threads:[~2014-04-28  9:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-28  9:49 [PATCH 1/6] environment: drop envfs_register_partition Sascha Hauer
2014-04-28  9:49 ` [PATCH 2/6] env: erase/protect in envfs_save Sascha Hauer
2014-04-28  9:49 ` [PATCH 3/6] mtd: nand: bb: use mtd api directly Sascha Hauer
2014-04-28 13:05   ` Alexander Aring
2014-04-28 18:48     ` Sascha Hauer
2014-04-28  9:49 ` Sascha Hauer [this message]
2014-04-28  9:49 ` [PATCH 5/6] mtd: nand: create bb devices automatically Sascha Hauer
2014-04-28  9:49 ` [PATCH 6/6] OF: barebox-env: Use bb device on NAND Sascha Hauer

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=1398678579-17491-4-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@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