From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-fx0-f228.google.com ([209.85.220.228]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1NdBAX-00074k-9O for linux-mtd@lists.infradead.org; Thu, 04 Feb 2010 23:31:37 +0000 Received: by mail-fx0-f228.google.com with SMTP id 28so3537637fxm.20 for ; Thu, 04 Feb 2010 15:31:29 -0800 (PST) From: Maxim Levitsky To: David Woodhouse Subject: [PATCH 08/17] MTD: call remove notifiers before removing the device Date: Fri, 5 Feb 2010 01:30:48 +0200 Message-Id: <1265326257-4446-9-git-send-email-maximlevitsky@gmail.com> In-Reply-To: <1265326257-4446-1-git-send-email-maximlevitsky@gmail.com> References: <1265326257-4446-1-git-send-email-maximlevitsky@gmail.com> Cc: Maxim Levitsky , Alex Dubov , Artem Bityutskiy , joern , linux-kernel , linux-mtd , Thomas Gleixner List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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. Signed-off-by: Maxim Levitsky --- drivers/mtd/mtdcore.c | 21 +++++++++++---------- 1 files changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 3bdb7e8..0e86208 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -341,31 +341,32 @@ int add_mtd_device(struct mtd_info *mtd) int del_mtd_device (struct mtd_info *mtd) { int ret; + struct mtd_notifier *not; mutex_lock(&mtd_table_mutex); if (mtd_table[mtd->index] != mtd) { 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", mtd->index, mtd->name, mtd->usecount); ret = -EBUSY; } else { - struct mtd_notifier *not; - 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); - mtd_table[mtd->index] = NULL; - module_put(THIS_MODULE); ret = 0; } +out_error: mutex_unlock(&mtd_table_mutex); return ret; } -- 1.6.3.3