9
0
Fork 0

mtd: add private data to mtddev-hook

The mtdoob and mtdraw device don't clean up correctly.
Added a private data element to hold allocated memory.
Fix remove of mtdoob and mtdraw device.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Alexander Aring 2012-09-03 07:58:01 +02:00 committed by Sascha Hauer
parent 06e5a6a5ca
commit 83f311a9bb
4 changed files with 35 additions and 6 deletions

View File

@ -248,7 +248,7 @@ int add_mtd_device(struct mtd_info *mtd, char *devname)
list_for_each_entry(hook, &mtd_register_hooks, hook)
if (hook->add_mtd_device)
hook->add_mtd_device(mtd, devname);
hook->add_mtd_device(mtd, devname, &hook->priv);
return 0;
}
@ -259,7 +259,9 @@ int del_mtd_device (struct mtd_info *mtd)
list_for_each_entry(hook, &mtd_register_hooks, hook)
if (hook->del_mtd_device)
hook->del_mtd_device(mtd);
hook->del_mtd_device(mtd, &hook->priv);
devfs_remove(&mtd->cdev);
unregister_device(&mtd->class_dev);
free(mtd->param_size.value);
free(mtd->cdev.name);

View File

@ -25,8 +25,9 @@
*/
struct mtddev_hook {
struct list_head hook;
int (*add_mtd_device)(struct mtd_info *mtd, char *devname);
int (*del_mtd_device)(struct mtd_info *mtd);
int (*add_mtd_device)(struct mtd_info *mtd, char *devname, void **priv);
int (*del_mtd_device)(struct mtd_info *mtd, void **priv);
void *priv;
};
struct cdev;

View File

@ -69,7 +69,7 @@ static struct file_operations mtd_ops_oob = {
.lseek = dev_lseek_default,
};
static int add_mtdoob_device(struct mtd_info *mtd, char *devname)
static int add_mtdoob_device(struct mtd_info *mtd, char *devname, void **priv)
{
struct mtdoob *mtdoob;
@ -80,13 +80,26 @@ static int add_mtdoob_device(struct mtd_info *mtd, char *devname)
mtdoob->cdev.priv = mtdoob;
mtdoob->cdev.dev = &mtd->class_dev;
mtdoob->mtd = mtd;
*priv = mtdoob;
devfs_create(&mtdoob->cdev);
return 0;
}
static int del_mtdoob_device(struct mtd_info *mtd, void **priv)
{
struct mtdoob *mtdoob;
mtdoob = *priv;
devfs_remove(&mtdoob->cdev);
free(mtdoob);
return 0;
}
static struct mtddev_hook mtdoob_hook = {
.add_mtd_device = add_mtdoob_device,
.del_mtd_device = del_mtdoob_device,
};
static int __init register_mtdoob(void)

View File

@ -275,7 +275,7 @@ static const struct file_operations mtd_raw_fops = {
.lseek = dev_lseek_default,
};
static int add_mtdraw_device(struct mtd_info *mtd, char *devname)
static int add_mtdraw_device(struct mtd_info *mtd, char *devname, void **priv)
{
struct mtdraw *mtdraw;
@ -290,13 +290,26 @@ static int add_mtdraw_device(struct mtd_info *mtd, char *devname)
mtdraw->cdev.priv = mtdraw;
mtdraw->cdev.dev = &mtd->class_dev;
mtdraw->cdev.mtd = mtd;
*priv = mtdraw;
devfs_create(&mtdraw->cdev);
return 0;
}
static int del_mtdraw_device(struct mtd_info *mtd, void **priv)
{
struct mtdraw *mtdraw;
mtdraw = *priv;
devfs_remove(&mtdraw->cdev);
free(mtdraw);
return 0;
}
static struct mtddev_hook mtdraw_hook = {
.add_mtd_device = add_mtdraw_device,
.del_mtd_device = del_mtdraw_device,
};
static int __init register_mtdraw(void)