提交 75c0b84d 编写于 作者: M Maxim Levitsky 提交者: David Woodhouse

mtd: call the remove notifiers before assuming it is in use

Now that mtd block common layer is prepared for proper hotplug support,
enable it here

Now all users of the mtd device have a chance to put the mtd device
when they are notified to do so, and they have to do so to make hotplug work.

[dwmw2: There's more work to be done to fix hotplug in the general case, but
        this is a reasonable start]
Signed-off-by: NMaxim Levitsky <maximlevitsky@gmail.com>
Signed-off-by: NDavid Woodhouse <David.Woodhouse@intel.com>
上级 298304f1
...@@ -350,31 +350,34 @@ int add_mtd_device(struct mtd_info *mtd) ...@@ -350,31 +350,34 @@ int add_mtd_device(struct mtd_info *mtd)
int del_mtd_device (struct mtd_info *mtd) int del_mtd_device (struct mtd_info *mtd)
{ {
int ret; int ret;
struct mtd_notifier *not;
mutex_lock(&mtd_table_mutex); mutex_lock(&mtd_table_mutex);
if (idr_find(&mtd_idr, mtd->index) != mtd) { if (idr_find(&mtd_idr, mtd->index) != mtd) {
ret = -ENODEV; ret = -ENODEV;
} else if (mtd->usecount) { goto out_error;
}
/* No need to get a refcount on the module containing
the notifier, since we hold the mtd_table_mutex */
list_for_each_entry(not, &mtd_notifiers, list)
not->remove(mtd);
if (mtd->usecount) {
printk(KERN_NOTICE "Removing MTD device #%d (%s) with use count %d\n", printk(KERN_NOTICE "Removing MTD device #%d (%s) with use count %d\n",
mtd->index, mtd->name, mtd->usecount); mtd->index, mtd->name, mtd->usecount);
ret = -EBUSY; ret = -EBUSY;
} else { } else {
struct mtd_notifier *not;
device_unregister(&mtd->dev); device_unregister(&mtd->dev);
/* No need to get a refcount on the module containing
the notifier, since we hold the mtd_table_mutex */
list_for_each_entry(not, &mtd_notifiers, list)
not->remove(mtd);
idr_remove(&mtd_idr, mtd->index); idr_remove(&mtd_idr, mtd->index);
module_put(THIS_MODULE); module_put(THIS_MODULE);
ret = 0; ret = 0;
} }
out_error:
mutex_unlock(&mtd_table_mutex); mutex_unlock(&mtd_table_mutex);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册