From f880d7bc875bc4165a9de8ad81ecf1ccb8307af7 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Fri, 8 Apr 2011 11:32:44 +0200 Subject: [PATCH] nand bb: add proper bb remove function 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 --- 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 ed55625ed..88f242df0 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 d71a2b0c6..dbfb8e38b 100644 --- a/drivers/mtd/nand/nand-bb.c +++ b/drivers/mtd/nand/nand-bb.c @@ -31,6 +31,7 @@ #include #include #include +#include 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 05358d021..b1762dfa4 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__ */