summaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorweiping zhang <zhangweiping@didichuxing.com>2017-10-17 18:56:21 +0300
committerJens Axboe <axboe@kernel.dk>2017-11-04 21:31:15 +0300
commite84010732225c4c7c3464ee1169d395751c3adfa (patch)
treee2d58f0a0f73d03edaa383e6fba1b2a9f15cd134 /block
parent88022d7201e96b43f1754b0358fc6bcd8dbdcde1 (diff)
downloadlinux-e84010732225c4c7c3464ee1169d395751c3adfa.tar.xz
blkcg: add sanity check for blkcg policy operations
blkcg policy should keep cpd/pd's alloc_fn and free_fn in pairs, otherwise policy would register fail. Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de> Signed-off-by: weiping zhang <zhangweiping@didichuxing.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block')
-rw-r--r--block/blk-cgroup.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index e7ec676043b1..4117524ca45b 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -1419,6 +1419,11 @@ int blkcg_policy_register(struct blkcg_policy *pol)
if (i >= BLKCG_MAX_POLS)
goto err_unlock;
+ /* Make sure cpd/pd_alloc_fn and cpd/pd_free_fn in pairs */
+ if ((!pol->cpd_alloc_fn ^ !pol->cpd_free_fn) ||
+ (!pol->pd_alloc_fn ^ !pol->pd_free_fn))
+ goto err_unlock;
+
/* register @pol */
pol->plid = i;
blkcg_policy[pol->plid] = pol;