]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - drivers/mtd/mtd_blkdevs.c
block: autoconvert trivial BKL users to private mutex
[net-next-2.6.git] / drivers / mtd / mtd_blkdevs.c
index 8c83b11a77d595123009f3a5d97832b29ac7fea6..50ab431b24ebafd456269061ac7a6873c152a57d 100644 (file)
@@ -1,7 +1,21 @@
 /*
- * (C) 2003 David Woodhouse <dwmw2@infradead.org>
+ * Interface to Linux block layer for MTD 'translation layers'.
  *
- * Interface to Linux 2.5 block layer for MTD 'translation layers'.
+ * Copyright © 2003-2010 David Woodhouse <dwmw2@infradead.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
 
@@ -15,7 +29,6 @@
 #include <linux/blkdev.h>
 #include <linux/blkpg.h>
 #include <linux/spinlock.h>
-#include <linux/smp_lock.h>
 #include <linux/hdreg.h>
 #include <linux/init.h>
 #include <linux/mutex.h>
@@ -24,6 +37,7 @@
 
 #include "mtdcore.h"
 
+static DEFINE_MUTEX(mtd_blkdevs_mutex);
 static LIST_HEAD(blktrans_majors);
 static DEFINE_MUTEX(blktrans_ref_mutex);
 
@@ -165,8 +179,9 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode)
        int ret;
 
        if (!dev)
-               return -ERESTARTSYS;
+               return -ERESTARTSYS; /* FIXME: busy loop! -arnd*/
 
+       mutex_lock(&mtd_blkdevs_mutex);
        mutex_lock(&dev->lock);
 
        if (!dev->mtd) {
@@ -183,6 +198,7 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode)
 unlock:
        mutex_unlock(&dev->lock);
        blktrans_dev_put(dev);
+       mutex_unlock(&mtd_blkdevs_mutex);
        return ret;
 }
 
@@ -194,6 +210,7 @@ static int blktrans_release(struct gendisk *disk, fmode_t mode)
        if (!dev)
                return ret;
 
+       mutex_lock(&mtd_blkdevs_mutex);
        mutex_lock(&dev->lock);
 
        /* Release one reference, we sure its not the last one here*/
@@ -206,6 +223,7 @@ static int blktrans_release(struct gendisk *disk, fmode_t mode)
 unlock:
        mutex_unlock(&dev->lock);
        blktrans_dev_put(dev);
+       mutex_unlock(&mtd_blkdevs_mutex);
        return ret;
 }
 
@@ -238,7 +256,7 @@ static int blktrans_ioctl(struct block_device *bdev, fmode_t mode,
        if (!dev)
                return ret;
 
-       lock_kernel();
+       mutex_lock(&mtd_blkdevs_mutex);
        mutex_lock(&dev->lock);
 
        if (!dev->mtd)
@@ -247,12 +265,13 @@ static int blktrans_ioctl(struct block_device *bdev, fmode_t mode,
        switch (cmd) {
        case BLKFLSBUF:
                ret = dev->tr->flush ? dev->tr->flush(dev) : 0;
+               break;
        default:
                ret = -ENOTTY;
        }
 unlock:
        mutex_unlock(&dev->lock);
-       unlock_kernel();
+       mutex_unlock(&mtd_blkdevs_mutex);
        blktrans_dev_put(dev);
        return ret;
 }
@@ -412,13 +431,14 @@ int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)
                BUG();
        }
 
-       /* Stop new requests to arrive */
-       del_gendisk(old->disk);
-
        if (old->disk_attributes)
                sysfs_remove_group(&disk_to_dev(old->disk)->kobj,
                                                old->disk_attributes);
 
+       /* Stop new requests to arrive */
+       del_gendisk(old->disk);
+
+
        /* Stop the thread */
        kthread_stop(old->thread);