9
0
Fork 0

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 <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2011-04-08 11:32:44 +02:00
parent e7c06800ee
commit f880d7bc87
3 changed files with 28 additions and 12 deletions

View File

@ -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++;
}
}

View File

@ -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;
}

View File

@ -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__ */