Merge tag 'v3.10.92' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / block / blk-cgroup.c
index b2b9837f9dd3475be841d41ed52dd7715e936d4b..8c4e81ac5e75432c1e29917dd6bf0305505ad7a6 100644 (file)
@@ -720,8 +720,12 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
                return -EINVAL;
 
        disk = get_gendisk(MKDEV(major, minor), &part);
-       if (!disk || part)
+       if (!disk)
                return -EINVAL;
+       if (part) {
+               put_disk(disk);
+               return -EINVAL;
+       }
 
        rcu_read_lock();
        spin_lock_irq(disk->queue->queue_lock);
@@ -876,6 +880,20 @@ void blkcg_drain_queue(struct request_queue *q)
 {
        lockdep_assert_held(q->queue_lock);
 
+       /*
+        * @q could be exiting and already have destroyed all blkgs as
+        * indicated by NULL root_blkg.  If so, don't confuse policies.
+        */
+       if (!q->root_blkg)
+               return;
+
+       /*
+        * @q could be exiting and already have destroyed all blkgs as
+        * indicated by NULL root_blkg.  If so, don't confuse policies.
+        */
+       if (!q->root_blkg)
+               return;
+
        blk_throtl_drain(q);
 }
 
@@ -972,10 +990,10 @@ int blkcg_activate_policy(struct request_queue *q,
        if (!new_blkg)
                return -ENOMEM;
 
-       preloaded = !radix_tree_preload(GFP_KERNEL);
-
        blk_queue_bypass_start(q);
 
+       preloaded = !radix_tree_preload(GFP_KERNEL);
+
        /*
         * Make sure the root blkg exists and count the existing blkgs.  As
         * @q is bypassing at this point, blkg_lookup_create() can't be