OSDN Git Service

blkcg: add sanity check for blkcg policy operations
authorweiping zhang <zhangweiping@didichuxing.com>
Tue, 17 Oct 2017 15:56:21 +0000 (23:56 +0800)
committerJens Axboe <axboe@kernel.dk>
Sat, 4 Nov 2017 18:31:15 +0000 (12:31 -0600)
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>
block/blk-cgroup.c

index e7ec676..4117524 100644 (file)
@@ -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;