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:
parent
06e5a6a5ca
commit
83f311a9bb
|
@ -248,7 +248,7 @@ int add_mtd_device(struct mtd_info *mtd, char *devname)
|
||||||
|
|
||||||
list_for_each_entry(hook, &mtd_register_hooks, hook)
|
list_for_each_entry(hook, &mtd_register_hooks, hook)
|
||||||
if (hook->add_mtd_device)
|
if (hook->add_mtd_device)
|
||||||
hook->add_mtd_device(mtd, devname);
|
hook->add_mtd_device(mtd, devname, &hook->priv);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -259,7 +259,9 @@ int del_mtd_device (struct mtd_info *mtd)
|
||||||
|
|
||||||
list_for_each_entry(hook, &mtd_register_hooks, hook)
|
list_for_each_entry(hook, &mtd_register_hooks, hook)
|
||||||
if (hook->del_mtd_device)
|
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);
|
unregister_device(&mtd->class_dev);
|
||||||
free(mtd->param_size.value);
|
free(mtd->param_size.value);
|
||||||
free(mtd->cdev.name);
|
free(mtd->cdev.name);
|
||||||
|
|
|
@ -25,8 +25,9 @@
|
||||||
*/
|
*/
|
||||||
struct mtddev_hook {
|
struct mtddev_hook {
|
||||||
struct list_head hook;
|
struct list_head hook;
|
||||||
int (*add_mtd_device)(struct mtd_info *mtd, char *devname);
|
int (*add_mtd_device)(struct mtd_info *mtd, char *devname, void **priv);
|
||||||
int (*del_mtd_device)(struct mtd_info *mtd);
|
int (*del_mtd_device)(struct mtd_info *mtd, void **priv);
|
||||||
|
void *priv;
|
||||||
};
|
};
|
||||||
struct cdev;
|
struct cdev;
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ static struct file_operations mtd_ops_oob = {
|
||||||
.lseek = dev_lseek_default,
|
.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;
|
struct mtdoob *mtdoob;
|
||||||
|
|
||||||
|
@ -80,13 +80,26 @@ static int add_mtdoob_device(struct mtd_info *mtd, char *devname)
|
||||||
mtdoob->cdev.priv = mtdoob;
|
mtdoob->cdev.priv = mtdoob;
|
||||||
mtdoob->cdev.dev = &mtd->class_dev;
|
mtdoob->cdev.dev = &mtd->class_dev;
|
||||||
mtdoob->mtd = mtd;
|
mtdoob->mtd = mtd;
|
||||||
|
*priv = mtdoob;
|
||||||
devfs_create(&mtdoob->cdev);
|
devfs_create(&mtdoob->cdev);
|
||||||
|
|
||||||
return 0;
|
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 = {
|
static struct mtddev_hook mtdoob_hook = {
|
||||||
.add_mtd_device = add_mtdoob_device,
|
.add_mtd_device = add_mtdoob_device,
|
||||||
|
.del_mtd_device = del_mtdoob_device,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int __init register_mtdoob(void)
|
static int __init register_mtdoob(void)
|
||||||
|
|
|
@ -275,7 +275,7 @@ static const struct file_operations mtd_raw_fops = {
|
||||||
.lseek = dev_lseek_default,
|
.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;
|
struct mtdraw *mtdraw;
|
||||||
|
|
||||||
|
@ -290,13 +290,26 @@ static int add_mtdraw_device(struct mtd_info *mtd, char *devname)
|
||||||
mtdraw->cdev.priv = mtdraw;
|
mtdraw->cdev.priv = mtdraw;
|
||||||
mtdraw->cdev.dev = &mtd->class_dev;
|
mtdraw->cdev.dev = &mtd->class_dev;
|
||||||
mtdraw->cdev.mtd = mtd;
|
mtdraw->cdev.mtd = mtd;
|
||||||
|
*priv = mtdraw;
|
||||||
devfs_create(&mtdraw->cdev);
|
devfs_create(&mtdraw->cdev);
|
||||||
|
|
||||||
return 0;
|
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 = {
|
static struct mtddev_hook mtdraw_hook = {
|
||||||
.add_mtd_device = add_mtdraw_device,
|
.add_mtd_device = add_mtdraw_device,
|
||||||
|
.del_mtd_device = del_mtdraw_device,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int __init register_mtdraw(void)
|
static int __init register_mtdraw(void)
|
||||||
|
|
Loading…
Reference in New Issue