[PATCH v4] blkcg: add sanity check for blkcg policy operations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



blkcg policy should keep cpd/pd's alloc_fn and free_fn in pairs,
otherwise policy would register fail.

Reviewed-by: Johannes Thumshirn <jthumshirn@xxxxxxx>
Signed-off-by: weiping zhang <zhangweiping@xxxxxxxxxxxxxxx>
---
Changes since V4:
 * merge "if(cpd->xxx)" and "if(pd->xxx)" together

Changes since V3:
 * make if more cleaner by using !pold->cpd_alloc_fn ^ !pol->cpd_free_fn

Chagnes since V2:
 * merge blkcg_policy_check_ops into the caller blkcg_policy_register

V1:
 * add blkcg_policy_check_ops to check cpd/pd's alloc_fn and free_fn in
 * pairs.

 block/blk-cgroup.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index e7ec676..4117524 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;
-- 
2.9.4




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux