netfilter: synproxy: fix manual bump of the reference counter
[sfrench/cifs-2.6.git] / block / blk-mq.c
index 08a6248d85365ea87fd414de9577885ee67838bf..32b8ad3d341b6dd2361978af56d0a34f2609011e 100644 (file)
@@ -144,13 +144,14 @@ void blk_mq_in_flight_rw(struct request_queue *q, struct hd_struct *part,
 
 void blk_freeze_queue_start(struct request_queue *q)
 {
-       int freeze_depth;
-
-       freeze_depth = atomic_inc_return(&q->mq_freeze_depth);
-       if (freeze_depth == 1) {
+       mutex_lock(&q->mq_freeze_lock);
+       if (++q->mq_freeze_depth == 1) {
                percpu_ref_kill(&q->q_usage_counter);
+               mutex_unlock(&q->mq_freeze_lock);
                if (queue_is_mq(q))
                        blk_mq_run_hw_queues(q, false);
+       } else {
+               mutex_unlock(&q->mq_freeze_lock);
        }
 }
 EXPORT_SYMBOL_GPL(blk_freeze_queue_start);
@@ -199,14 +200,14 @@ EXPORT_SYMBOL_GPL(blk_mq_freeze_queue);
 
 void blk_mq_unfreeze_queue(struct request_queue *q)
 {
-       int freeze_depth;
-
-       freeze_depth = atomic_dec_return(&q->mq_freeze_depth);
-       WARN_ON_ONCE(freeze_depth < 0);
-       if (!freeze_depth) {
+       mutex_lock(&q->mq_freeze_lock);
+       q->mq_freeze_depth--;
+       WARN_ON_ONCE(q->mq_freeze_depth < 0);
+       if (!q->mq_freeze_depth) {
                percpu_ref_resurrect(&q->q_usage_counter);
                wake_up_all(&q->mq_freeze_wq);
        }
+       mutex_unlock(&q->mq_freeze_lock);
 }
 EXPORT_SYMBOL_GPL(blk_mq_unfreeze_queue);