From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 4/4] nand bb: add proper bb remove function
Date: Mon, 11 Apr 2011 16:11:51 +0200 [thread overview]
Message-ID: <1302531111-29244-5-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1302531111-29244-1-git-send-email-s.hauer@pengutronix.de>
The old way happily removed cdev entries which were no bb dev
at all. Fix this by checking if the given device actually is
a bb device.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/nand.c | 13 +------------
drivers/mtd/nand/nand-bb.c | 22 ++++++++++++++++++++++
include/nand.h | 5 +++++
3 files changed, 28 insertions(+), 12 deletions(-)
diff --git a/commands/nand.c b/commands/nand.c
index ed55625..88f242d 100644
--- a/commands/nand.c
+++ b/commands/nand.c
@@ -39,7 +39,6 @@
static int do_nand(struct command *cmdtp, int argc, char *argv[])
{
int opt;
- struct nand_bb *bb;
int command = 0, badblock = 0;
while((opt = getopt(argc, argv, "adb:")) > 0) {
@@ -72,17 +71,7 @@ static int do_nand(struct command *cmdtp, int argc, char *argv[])
if (command & NAND_DEL) {
while (optind < argc) {
- struct cdev *cdev;
-
- cdev = cdev_by_name(basename(argv[optind]));
- if (!cdev) {
- printf("no such device: %s\n", argv[optind]);
- return 1;
- }
- bb = cdev->priv;
- close(bb->fd);
- devfs_remove(cdev);
- free(bb);
+ dev_remove_bb_dev(basename(argv[optind]));
optind++;
}
}
diff --git a/drivers/mtd/nand/nand-bb.c b/drivers/mtd/nand/nand-bb.c
index d71a2b0..dbfb8e3 100644
--- a/drivers/mtd/nand/nand-bb.c
+++ b/drivers/mtd/nand/nand-bb.c
@@ -31,6 +31,7 @@
#include <linux/mtd/mtd-abi.h>
#include <fcntl.h>
#include <libgen.h>
+#include <linux/list.h>
struct nand_bb {
char cdevname[MAX_DRIVER_NAME];
@@ -47,6 +48,8 @@ struct nand_bb {
void *writebuf;
struct cdev cdev;
+
+ struct list_head list;
};
static ssize_t nand_bb_read(struct cdev *cdev, void *buf, size_t count,
@@ -218,6 +221,8 @@ static struct file_operations nand_bb_ops = {
#endif
};
+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
@@ -258,6 +263,8 @@ int dev_add_bb_dev(char *path, const char *name)
if (ret)
goto out4;
+ list_add_tail(&bb->list, &bb_list);
+
return 0;
out4:
@@ -267,3 +274,18 @@ out1:
return ret;
}
+int dev_remove_bb_dev(const char *name)
+{
+ struct nand_bb *bb;
+
+ list_for_each_entry(bb, &bb_list, list) {
+ if (!strcmp(bb->cdev.name, name)) {
+ devfs_remove(&bb->cdev);
+ cdev_close(bb->cdev_parent);
+ free(bb);
+ return 0;
+ }
+ }
+
+ return -ENODEV;
+}
diff --git a/include/nand.h b/include/nand.h
index 05358d0..b1762df 100644
--- a/include/nand.h
+++ b/include/nand.h
@@ -6,10 +6,15 @@ struct nand_bb;
#ifdef CONFIG_NAND
int dev_add_bb_dev(char *filename, const char *name);
+int dev_remove_bb_dev(const char *name);
#else
static inline int dev_add_bb_dev(char *filename, const char *name) {
return 0;
}
+static inline int dev_remove_bb_dev(const char *name)
+{
+ return 0;
+}
#endif
#endif /* __NAND_H__ */
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
prev parent reply other threads:[~2011-04-11 14:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-11 14:11 nand patches Sascha Hauer
2011-04-11 14:11 ` [PATCH 1/4] nand: nand_block_markbad is only used with nand write support Sascha Hauer
2011-04-11 14:11 ` [PATCH 2/4] nand: move bb handling code to drivers/mtd/nand Sascha Hauer
2011-04-11 14:11 ` [PATCH 3/4] nand bb: switch to cdev operations Sascha Hauer
2011-04-11 14:11 ` Sascha Hauer [this message]
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=1302531111-29244-5-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