blkcg: add sanity check for blkcg policy operations
Subsystems (2)
PATCH v2 1/1 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.
Signed-off-by weiping zhang <[email protected]>
--- block/blk-cgroup.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
block/blk-cgroup.c +10 -0
@@ -1419,6 +1419,16 @@ int blkcg_policy_register(struct blkcg_policy *pol)if (i >=BLKCG_MAX_POLS ) goto err_unlock; +/* Make sure cpd_alloc_fn and cpd_free_fn in pairs */ +if ((pol->cpd_alloc_fn && !pol->cpd_free_fn) || + (!pol->cpd_alloc_fn && pol->cpd_free_fn)) + goto err_unlock; + +/* Make sure pd_alloc_fn and pd_free_fn in pairs */ +if ((pol->pd_alloc_fn && !pol->pd_free_fn) || + (!pol->pd_alloc_fn && pol->pd_free_fn)) + goto err_unlock; +/* register @pol */ pol->plid = i; blkcg_policy[pol->plid] = pol;
Signature · 1 line
2.9.4
Jens Axboe
maintainerQuoted 13 lines · weiping zhang
blkcg policy should keep cpd/pd's
alloc_fnandfree_fnin pairs, otherwise policy would register fail.Signed-off-by weiping zhang <[email protected]>--- block/blk-cgroup.c | 10 ++++++++++ 1 file changed, 10 insertions(+)block/blk-cgroup.c +0
-0
block/blk-cgroup.c int blkcg_policy_register(struct blkcg_policy *pol) · line 1425
Quoted 7 lines
block/blk-cgroup.c +4
-0@@ -1419,6 +1419,16 @@ int blkcg_policy_register(struct blkcg_policy *pol)if (i >=BLKCG_MAX_POLS ) goto err_unlock; +/* Make sure cpd_alloc_fn and cpd_free_fn in pairs */ +if ((pol->cpd_alloc_fn && !pol->cpd_free_fn) || + (!pol->cpd_alloc_fn && pol->cpd_free_fn)) + goto err_unlock;
This might be cleaner (and more readable) as:
if (!pol->cpd_alloc_fn ^ !pol->cpd_free_fn)
goto err_unlock;Ditto for the pd part.
Signature · 1 line
Jens Axboe
Quoted 24 lines · Jens Axboe
Quoted 13 lines · weiping zhang
blkcg policy should keep cpd/pd's
alloc_fnandfree_fnin pairs, otherwise policy would register fail.Signed-off-by weiping zhang <[email protected]>--- block/blk-cgroup.c | 10 ++++++++++ 1 file changed, 10 insertions(+)block/blk-cgroup.c +0
-0block/blk-cgroup.c int blkcg_policy_register(struct blkcg_policy *pol) · line 1425
Quoted 7 lines
block/blk-cgroup.c +4
-0@@ -1419,6 +1419,16 @@ int blkcg_policy_register(struct blkcg_policy *pol)if (i >=BLKCG_MAX_POLS ) goto err_unlock; +/* Make sure cpd_alloc_fn and cpd_free_fn in pairs */ +if ((pol->cpd_alloc_fn && !pol->cpd_free_fn) || + (!pol->cpd_alloc_fn && pol->cpd_free_fn)) + goto err_unlock;This might be cleaner (and more readable) as:
Quoted 5 lines
if (!pol->cpd_alloc_fn ^ !pol->cpd_free_fn) goto err_unlock;Ditto for the pd part.
Really nice, I'll send v3.
Thanks