Skip to content

Commit

Permalink
blkcg: add sanity check for blkcg policy operations
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
weiping zhang authored and Jens Axboe committed Nov 4, 2017
1 parent 88022d7 commit e840107
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions block/blk-cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e840107

Please sign in to comment.