Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e8401073 authored by weiping zhang's avatar weiping zhang Committed by Jens Axboe
Browse files

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: default avatarJohannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: default avatarweiping zhang <zhangweiping@didichuxing.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 88022d72
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -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;