mtd: refactor bb device creation
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>
This commit is contained in:
parent
b32cd8df87
commit
33d4f7cb3d
|
@ -29,6 +29,7 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <linux/list.h>
|
#include <linux/list.h>
|
||||||
|
#include <linux/err.h>
|
||||||
|
|
||||||
struct nand_bb {
|
struct nand_bb {
|
||||||
char *name;
|
char *name;
|
||||||
|
@ -240,6 +241,36 @@ static struct file_operations nand_bb_ops = {
|
||||||
|
|
||||||
static LIST_HEAD(bb_list);
|
static LIST_HEAD(bb_list);
|
||||||
|
|
||||||
|
struct cdev *mtd_add_bb(struct mtd_info *mtd, const char *name)
|
||||||
|
{
|
||||||
|
struct nand_bb *bb;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
bb = xzalloc(sizeof(*bb));
|
||||||
|
bb->mtd = mtd;
|
||||||
|
|
||||||
|
if (name)
|
||||||
|
bb->cdev.name = xstrdup(name);
|
||||||
|
else
|
||||||
|
bb->cdev.name = asprintf("%s.bb", mtd->cdev.name);
|
||||||
|
|
||||||
|
nand_bb_calc_size(bb);
|
||||||
|
bb->cdev.ops = &nand_bb_ops;
|
||||||
|
bb->cdev.priv = bb;
|
||||||
|
|
||||||
|
ret = devfs_create(&bb->cdev);
|
||||||
|
if (ret)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
list_add_tail(&bb->list, &bb_list);
|
||||||
|
|
||||||
|
return &bb->cdev;
|
||||||
|
|
||||||
|
err:
|
||||||
|
free(bb);
|
||||||
|
return ERR_PTR(ret);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a bad block aware device ontop of another (NAND) device
|
* Add a bad block aware device ontop of another (NAND) device
|
||||||
* @param[in] dev The device to add a partition on
|
* @param[in] dev The device to add a partition on
|
||||||
|
@ -248,9 +279,7 @@ static LIST_HEAD(bb_list);
|
||||||
*/
|
*/
|
||||||
int dev_add_bb_dev(const char *path, const char *name)
|
int dev_add_bb_dev(const char *path, const char *name)
|
||||||
{
|
{
|
||||||
struct nand_bb *bb;
|
struct cdev *parent, *cdev;
|
||||||
struct cdev *parent;
|
|
||||||
int ret = -ENOMEM;
|
|
||||||
|
|
||||||
parent = cdev_by_name(path);
|
parent = cdev_by_name(path);
|
||||||
if (!parent)
|
if (!parent)
|
||||||
|
@ -259,29 +288,9 @@ int dev_add_bb_dev(const char *path, const char *name)
|
||||||
if (!parent->mtd)
|
if (!parent->mtd)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
bb = xzalloc(sizeof(*bb));
|
cdev = mtd_add_bb(parent->mtd, name);
|
||||||
bb->mtd = parent->mtd;
|
|
||||||
|
|
||||||
if (name)
|
return PTR_ERR(cdev);
|
||||||
bb->cdev.name = xstrdup(name);
|
|
||||||
else
|
|
||||||
bb->cdev.name = asprintf("%s.bb", path);;
|
|
||||||
|
|
||||||
nand_bb_calc_size(bb);
|
|
||||||
bb->cdev.ops = &nand_bb_ops;
|
|
||||||
bb->cdev.priv = bb;
|
|
||||||
|
|
||||||
ret = devfs_create(&bb->cdev);
|
|
||||||
if (ret)
|
|
||||||
goto out4;
|
|
||||||
|
|
||||||
list_add_tail(&bb->list, &bb_list);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
out4:
|
|
||||||
free(bb);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int dev_remove_bb_dev(const char *name)
|
int dev_remove_bb_dev(const char *name)
|
||||||
|
|
|
@ -7,6 +7,7 @@ struct nand_bb;
|
||||||
#ifdef CONFIG_NAND
|
#ifdef CONFIG_NAND
|
||||||
int dev_add_bb_dev(const char *filename, const char *name);
|
int dev_add_bb_dev(const char *filename, const char *name);
|
||||||
int dev_remove_bb_dev(const char *name);
|
int dev_remove_bb_dev(const char *name);
|
||||||
|
struct cdev *mtd_add_bb(struct mtd_info *mtd, const char *name);
|
||||||
#else
|
#else
|
||||||
static inline int dev_add_bb_dev(const char *filename, const char *name) {
|
static inline int dev_add_bb_dev(const char *filename, const char *name) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -15,6 +16,11 @@ static inline int dev_remove_bb_dev(const char *name)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline struct cdev *mtd_add_bb(struct mtd_info *mtd, const char *name)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* __NAND_H__ */
|
#endif /* __NAND_H__ */
|
||||||
|
|
Loading…
Reference in New Issue