@@ -23,20 +23,29 @@
/* Implicitly serialized by the domctl lock. */
int vm_event_init_domain(struct domain *d)
{
+ int rc = 0;
struct vcpu *v;
+ /* Per-vcpu initializations. */
for_each_vcpu ( d, v )
{
- if ( v->arch.vm_event )
+ if ( unlikely(v->arch.vm_event) )
continue;
v->arch.vm_event = xzalloc(struct arch_vm_event);
-
- if ( !v->arch.vm_event )
- return -ENOMEM;
+ if ( unlikely(!v->arch.vm_event) )
+ {
+ rc = -ENOMEM;
+ goto err;
+ }
}
- return 0;
+err:
+ if ( unlikely(rc) )
+ /* On fail cleanup whatever resources have been partially allocated. */
+ vm_event_cleanup_domain(d);
+
+ return rc;
}
/*
@@ -47,6 +56,7 @@ void vm_event_cleanup_domain(struct domain *d)
{
struct vcpu *v;
+ /* Per-vcpu uninitializations. */
for_each_vcpu ( d, v )
{
xfree(v->arch.vm_event);
From vm_event_init_domain(d), call vm_event_cleanup_domain(d) if per-vcpu allocations failed -at some point- to cleanup partial allocations, if any were done along the way. Also minor adjustments: add unlikely in if's and add some comments. Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com> --- xen/arch/x86/vm_event.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)