Skip to content

Commit 75c0b84

Browse files
maximlevitskyDavid Woodhouse
authored andcommitted
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: Maxim Levitsky <maximlevitsky@gmail.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent 298304f commit 75c0b84

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

‎drivers/mtd/mtdcore.c‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -350,31 +350,34 @@ int add_mtd_device(struct mtd_info *mtd)
350350
int del_mtd_device (struct mtd_info *mtd)
351351
{
352352
int ret;
353+
struct mtd_notifier *not;
353354

354355
mutex_lock(&mtd_table_mutex);
355356

356357
if (idr_find(&mtd_idr, mtd->index) != mtd) {
357358
ret = -ENODEV;
358-
} else if (mtd->usecount) {
359+
goto out_error;
360+
}
361+
362+
/* No need to get a refcount on the module containing
363+
the notifier, since we hold the mtd_table_mutex */
364+
list_for_each_entry(not, &mtd_notifiers, list)
365+
not->remove(mtd);
366+
367+
if (mtd->usecount) {
359368
printk(KERN_NOTICE "Removing MTD device #%d (%s) with use count %d\n",
360369
mtd->index, mtd->name, mtd->usecount);
361370
ret = -EBUSY;
362371
} else {
363-
struct mtd_notifier *not;
364-
365372
device_unregister(&mtd->dev);
366373

367-
/* No need to get a refcount on the module containing
368-
the notifier, since we hold the mtd_table_mutex */
369-
list_for_each_entry(not, &mtd_notifiers, list)
370-
not->remove(mtd);
371-
372374
idr_remove(&mtd_idr, mtd->index);
373375

374376
module_put(THIS_MODULE);
375377
ret = 0;
376378
}
377379

380+
out_error:
378381
mutex_unlock(&mtd_table_mutex);
379382
return ret;
380383
}

0 commit comments

Comments
 (0)