Thread (3 messages) 3 messages, 2 authors, 2016-09-29

[PATCH] blkcg: Unlock blkcg_pol_mutex once if cpd == NULL

flat view
STALE3663d

From: Bart Van Assche <hidden>
Date: 2016-09-26 22:36:35
Subsystem: block layer, control group - block io controller (blkio), the rest · Maintainers: Jens Axboe, Tejun Heo, Josef Bacik, Linus Torvalds

Unlocking a mutex twice is wrong. Hence modify blkcg_policy_register()
such that blkcg_pol_mutex is unlocked once if cpd == NULL. This patch
avoids that smatch reports the following error:

block/blk-cgroup.c:1378: blkcg_policy_register() error: double unlock 'mutex:&blkcg_pol_mutex'

Signed-off-by: Bart Van Assche <redacted>
Cc: Tejun Heo <tj@kernel.org>
Cc: <redacted>
---
 block/blk-cgroup.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index dd38e5c..cdbca1c 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -1327,8 +1327,10 @@ int blkcg_policy_register(struct blkcg_policy *pol)
 	for (i = 0; i < BLKCG_MAX_POLS; i++)
 		if (!blkcg_policy[i])
 			break;
-	if (i >= BLKCG_MAX_POLS)
+	if (i >= BLKCG_MAX_POLS) {
+		mutex_unlock(&blkcg_pol_mutex);
 		goto err_unlock;
+	}
 
 	/* register @pol */
 	pol->plid = i;
@@ -1374,8 +1376,8 @@ err_free_cpds:
 		}
 	}
 	blkcg_policy[pol->plid] = NULL;
+
 err_unlock:
-	mutex_unlock(&blkcg_pol_mutex);
 	mutex_unlock(&blkcg_pol_register_mutex);
 	return ret;
 }
-- 
2.10.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help