]> xenbits.xensource.com Git - people/liuw/xtf.git/commitdiff
Use IS_DEFINED() in preference to #ifdef
authorAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 11 May 2016 12:56:33 +0000 (13:56 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 11 May 2016 13:02:16 +0000 (14:02 +0100)
By exposing more code and having the compiler optimise it out, there is less
chance of bitrot.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
arch/x86/setup.c
tests/cpuid/main.c

index 6eaacc4707a86a635b6b705f864649739d6914da..3036fc8d4089c323f8405d4657302fc3bb98d2c2 100644 (file)
@@ -31,32 +31,33 @@ start_info_t *start_info = NULL;
  */
 static void init_hypercalls(void)
 {
-#ifdef CONFIG_HVM
-    uint32_t eax, ebx, ecx, edx, base;
-    bool found = false;
-
-    for ( base = XEN_CPUID_FIRST_LEAF;
-          base < XEN_CPUID_FIRST_LEAF + 0x10000; base += 0x100 )
+    if ( IS_DEFINED(CONFIG_HVM) )
     {
-        cpuid(base, &eax, &ebx, &ecx, &edx);
+        uint32_t eax, ebx, ecx, edx, base;
+        bool found = false;
 
-        if ( (ebx == XEN_CPUID_SIGNATURE_EBX) &&
-             (ecx == XEN_CPUID_SIGNATURE_ECX) &&
-             (edx == XEN_CPUID_SIGNATURE_EDX) &&
-             ((eax - base) >= 2) )
+        for ( base = XEN_CPUID_FIRST_LEAF;
+              base < XEN_CPUID_FIRST_LEAF + 0x10000; base += 0x100 )
         {
-            found = true;
-            break;
+            cpuid(base, &eax, &ebx, &ecx, &edx);
+
+            if ( (ebx == XEN_CPUID_SIGNATURE_EBX) &&
+                 (ecx == XEN_CPUID_SIGNATURE_ECX) &&
+                 (edx == XEN_CPUID_SIGNATURE_EDX) &&
+                 ((eax - base) >= 2) )
+            {
+                found = true;
+                break;
+            }
         }
-    }
 
-    if ( !found )
-        panic("Unable to locate Xen CPUID leaves\n");
+        if ( !found )
+            panic("Unable to locate Xen CPUID leaves\n");
 
-    cpuid(base + 2, &eax, &ebx, &ecx, &edx);
-    wrmsr(ebx, (unsigned long)&hypercall_page);
-    barrier();
-#endif /* CONFIG_HVM */
+        cpuid(base + 2, &eax, &ebx, &ecx, &edx);
+        wrmsr(ebx, (unsigned long)&hypercall_page);
+        barrier();
+    }
 
     /*
      * Confirm that the `ret` poision has been overwritten with a real
@@ -91,14 +92,12 @@ static void setup_pv_console(void)
     init_pv_console(cons_ring, cons_evtchn);
 }
 
-#if defined(CONFIG_HVM)
 static void qemu_console_write(const char *buf, size_t len)
 {
     asm volatile("rep; outsb"
                  : "+S" (buf), "+c" (len)
                  : "d" (0x12));
 }
-#endif
 
 static void xen_console_write(const char *buf, size_t len)
 {
@@ -107,9 +106,8 @@ static void xen_console_write(const char *buf, size_t len)
 
 void arch_setup(void)
 {
-#if defined(CONFIG_HVM)
-    register_console_callback(qemu_console_write);
-#endif
+    if ( IS_DEFINED(CONFIG_HVM) )
+        register_console_callback(qemu_console_write);
 
     register_console_callback(xen_console_write);
 
index bdb9a2300e31f4d3b6e1110e6908fcb2fa41ee35..f07cf1cf30e6849bd1b4c63bb285b300c1001b77 100644 (file)
@@ -99,10 +99,11 @@ void test_main(void)
     printk("Native cpuid:\n");
     dump_leaves(cpuid_count);
 
-#ifdef CONFIG_PV
-    printk("Emulated cpuid:\n");
-    dump_leaves(pv_cpuid_count);
-#endif
+    if ( IS_DEFINED(CONFIG_PV) )
+    {
+        printk("Emulated cpuid:\n");
+        dump_leaves(pv_cpuid_count);
+    }
 
     xtf_success(NULL);
 }