[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 07/16] x86/vm-event: fix: call cleanup when init fails, to free partial allocs
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@xxxxxxxxxxxxxxx> --- xen/arch/x86/vm_event.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/vm_event.c b/xen/arch/x86/vm_event.c index 6e19df8..22c63ea 100644 --- a/xen/arch/x86/vm_event.c +++ b/xen/arch/x86/vm_event.c @@ -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); -- 2.5.0 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |