OSDN Git Service

Merge tag 'for-4.15/dm-changes-2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[tomoyo/tomoyo-test1.git] / block / blk-cgroup.c
index d3f56ba..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;
@@ -1452,7 +1457,7 @@ int blkcg_policy_register(struct blkcg_policy *pol)
        return 0;
 
 err_free_cpds:
-       if (pol->cpd_alloc_fn) {
+       if (pol->cpd_free_fn) {
                list_for_each_entry(blkcg, &all_blkcgs, all_blkcgs_node) {
                        if (blkcg->cpd[pol->plid]) {
                                pol->cpd_free_fn(blkcg->cpd[pol->plid]);
@@ -1492,7 +1497,7 @@ void blkcg_policy_unregister(struct blkcg_policy *pol)
        /* remove cpds and unregister */
        mutex_lock(&blkcg_pol_mutex);
 
-       if (pol->cpd_alloc_fn) {
+       if (pol->cpd_free_fn) {
                list_for_each_entry(blkcg, &all_blkcgs, all_blkcgs_node) {
                        if (blkcg->cpd[pol->plid]) {
                                pol->cpd_free_fn(blkcg->cpd[pol->plid]);