Commit 087a61be authored by James Morse's avatar James Morse Committed by Wenkuan Wang
Browse files

x86/resctrl: Group struct rdt_hw_domain cleanup

mainline inclusion
from mainline-v6.1-rc1
commit 7add3af4
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I9U2JC


CVE: NA

--------------------------------

domain_add_cpu() and domain_remove_cpu() need to kfree() the child
arrays that were allocated by domain_setup_ctrlval().

As this memory is moved around, and new arrays are created, adjusting
the error handling cleanup code becomes noisier.

To simplify this, move all the kfree() calls into a domain_free() helper.
This depends on struct rdt_hw_domain being kzalloc()d, allowing it to
unconditionally kfree() all the child arrays.

Signed-off-by: default avatarJames Morse <james.morse@arm.com>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Reviewed-by: default avatarJamie Iles <quic_jiles@quicinc.com>
Reviewed-by: default avatarShaopeng Tan <tan.shaopeng@fujitsu.com>
Reviewed-by: default avatarReinette Chatre <reinette.chatre@intel.com>
Tested-by: default avatarXin Hao <xhao@linux.alibaba.com>
Tested-by: default avatarShaopeng Tan <tan.shaopeng@fujitsu.com>
Tested-by: default avatarCristian Marussi <cristian.marussi@arm.com>
Link: https://lore.kernel.org/r/20220902154829.30399-5-james.morse@arm.com


Signed-off-by: default avatarWenkuan Wang <Wenkuan.Wang@amd.com>
parent 8f264d10
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -535,6 +535,13 @@ void setup_default_ctrlval(struct rdt_resource *r, u32 *dc, u32 *dm)
	}
}

static void domain_free(struct rdt_hw_domain *hw_dom)
{
	kfree(hw_dom->ctrl_val);
	kfree(hw_dom->mbps_val);
	kfree(hw_dom);
}

static int domain_setup_ctrlval(struct rdt_resource *r, struct rdt_domain *d)
{
	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
@@ -607,7 +614,7 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)
	rdt_domain_reconfigure_cdp(r);

	if (r->alloc_capable && domain_setup_ctrlval(r, d)) {
		kfree(hw_dom);
		domain_free(hw_dom);
		return;
	}

@@ -616,9 +623,7 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r)
	err = resctrl_online_domain(r, d);
	if (err) {
		list_del(&d->list);
		kfree(hw_dom->ctrl_val);
		kfree(hw_dom->mbps_val);
		kfree(hw_dom);
		domain_free(hw_dom);
	}
}

@@ -666,12 +671,10 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r)
		if (d->plr)
			d->plr->d = NULL;

		kfree(hw_dom->ctrl_val);
		kfree(hw_dom->mbps_val);
		bitmap_free(d->rmid_busy_llc);
		kfree(d->mbm_total);
		kfree(d->mbm_local);
		kfree(hw_dom);
		domain_free(hw_dom);
		return;
	}