From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fg-out-1718.google.com ([72.14.220.153]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1NYLVv-0000Sx-B0 for linux-mtd@lists.infradead.org; Fri, 22 Jan 2010 15:33:39 +0000 Received: by fg-out-1718.google.com with SMTP id 22so53890fge.0 for ; Fri, 22 Jan 2010 07:33:32 -0800 (PST) Subject: [PATCH 1/4] MTD: call remove notifiers before removing the device From: Maxim Levitsky To: David Woodhouse In-Reply-To: <1264174316.24012.17.camel@maxim-laptop> References: <1264174316.24012.17.camel@maxim-laptop> Content-Type: text/plain; charset="UTF-8" Date: Fri, 22 Jan 2010 17:33:27 +0200 Message-ID: <1264174407.24012.19.camel@maxim-laptop> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Cc: Thomas Gleixner , joern , linux-mtd , linux-kernel , Alex Dubov List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , >>From e74bb4a1e1222ec35fa8ed0d0d40b8e3607992d8 Mon Sep 17 00:00:00 2001 From: Maxim Levitsky Date: Fri, 22 Jan 2010 15:00:53 +0200 Subject: [PATCH 1/4] MTD: call remove notifiers before removing the device This is first step in implementing proper hotplug support. 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 c356c0a..87ff83f 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