block: fix ext_devt_idr handling
[pandora-kernel.git] / block / genhd.c
index 4927476..ac9aeb4 100644 (file)
@@ -421,14 +421,18 @@ int blk_alloc_devt(struct hd_struct *part, dev_t *devt)
        do {
                if (!idr_pre_get(&ext_devt_idr, GFP_KERNEL))
                        return -ENOMEM;
+               mutex_lock(&ext_devt_mutex);
                rc = idr_get_new(&ext_devt_idr, part, &idx);
+               mutex_unlock(&ext_devt_mutex);
        } while (rc == -EAGAIN);
 
        if (rc)
                return rc;
 
        if (idx > MAX_EXT_DEVT) {
+               mutex_lock(&ext_devt_mutex);
                idr_remove(&ext_devt_idr, idx);
+               mutex_unlock(&ext_devt_mutex);
                return -EBUSY;
        }
 
@@ -645,7 +649,6 @@ void del_gendisk(struct gendisk *disk)
        disk_part_iter_exit(&piter);
 
        invalidate_partition(disk, 0);
-       blk_free_devt(disk_to_dev(disk)->devt);
        set_capacity(disk, 0);
        disk->flags &= ~GENHD_FL_UP;
 
@@ -663,6 +666,7 @@ void del_gendisk(struct gendisk *disk)
        if (!sysfs_deprecated)
                sysfs_remove_link(block_depr, dev_name(disk_to_dev(disk)));
        device_del(disk_to_dev(disk));
+       blk_free_devt(disk_to_dev(disk)->devt);
 }
 EXPORT_SYMBOL(del_gendisk);