diff mbox

[06/16] x86/monitor: fix: set msr_bitmap to NULL after xfree

Message ID 1468037757-6708-1-git-send-email-czuzu@bitdefender.com (mailing list archive)
State New, archived
Headers show

Commit Message

Corneliu ZUZU July 9, 2016, 4:15 a.m. UTC
Fix: set d->arch.monitor.msr_bitmap to NULL after xfree, as the equivalence of
it being NULL and xfreed is repeatedly presumed in the codebase. Along with this
change, also properly reposition an 'if' targeting the aforementioned msr_bitmap
when it is allocated and add likely/unlikely accordingly.

Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
---
 xen/arch/x86/monitor.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/xen/arch/x86/monitor.c b/xen/arch/x86/monitor.c
index 29188e5..8f41f21 100644
--- a/xen/arch/x86/monitor.c
+++ b/xen/arch/x86/monitor.c
@@ -54,11 +54,12 @@  static inline void monitor_ctrlreg_disable_traps(struct domain *d)
 
 int monitor_init_domain(struct domain *d)
 {
-    if ( !d->arch.monitor.msr_bitmap )
+    if ( likely(!d->arch.monitor.msr_bitmap) )
+    {
         d->arch.monitor.msr_bitmap = xzalloc(struct monitor_msr_bitmap);
-
-    if ( !d->arch.monitor.msr_bitmap )
-        return -ENOMEM;
+        if ( unlikely(!d->arch.monitor.msr_bitmap) )
+            return -ENOMEM;
+    }
 
     return 0;
 }
@@ -66,6 +67,7 @@  int monitor_init_domain(struct domain *d)
 void monitor_cleanup_domain(struct domain *d)
 {
     xfree(d->arch.monitor.msr_bitmap);
+    d->arch.monitor.msr_bitmap = NULL;
 
     monitor_ctrlreg_disable_traps(d);