]> xenbits.xensource.com Git - xen.git/commitdiff
x86: avoid overriding initialisers in arrays
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 11 Feb 2016 15:44:01 +0000 (16:44 +0100)
committerJan Beulich <jbeulich@suse.com>
Thu, 11 Feb 2016 15:44:01 +0000 (16:44 +0100)
Clang objects to having multiple initialisers when creating an array.

As this warning is useful for spotting obscure bugs, disabling it is
unhelpful.  Instead, fix our two deliberate usecases.

In the p2m-ept case, pull the array out into a helper function, so the helper
can guarentee to cover the NULL pointer case.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: George Dunlap <george.dunlap@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/cpu/mtrr/generic.c
xen/arch/x86/mm/p2m-ept.c

index ea0efe2f2ed71143b8e5af2cc6c1b6ef4ba6a826..8839f8d8e0a29c5d391ae407e577931013b47deb 100644 (file)
@@ -91,7 +91,6 @@ static const char *__init mtrr_attrib_to_str(mtrr_type x)
 {
        static const char __initconst strings[MTRR_NUM_TYPES][16] =
        {
-               [0 ... MTRR_NUM_TYPES - 1] = "?",
                [MTRR_TYPE_UNCACHABLE]     = "uncachable",
                [MTRR_TYPE_WRCOMB]         = "write-combining",
                [MTRR_TYPE_WRTHROUGH]      = "write-through",
@@ -99,7 +98,7 @@ static const char *__init mtrr_attrib_to_str(mtrr_type x)
                [MTRR_TYPE_WRBACK]         = "write-back",
        };
 
-       return x < MTRR_NUM_TYPES ? strings[x] : "?";
+       return x < MTRR_NUM_TYPES ? (strings[x] ?: "?") : "?";
 }
 
 static unsigned int __initdata last_fixed_start;
index c094320b2f6e061b9869b28cb458e3bc2e48f7df..c5fe906da90aa8faebfd3076fb04ec9b49761d6f 100644 (file)
@@ -1201,6 +1201,20 @@ void ept_p2m_uninit(struct p2m_domain *p2m)
     free_cpumask_var(ept->invalidate);
 }
 
+static const char *memory_type_to_str(unsigned int x)
+{
+    static const char memory_types[8][2] = {
+        [MTRR_TYPE_UNCACHABLE]     = "UC",
+        [MTRR_TYPE_WRCOMB]         = "WC",
+        [MTRR_TYPE_WRTHROUGH]      = "WT",
+        [MTRR_TYPE_WRPROT]         = "WP",
+        [MTRR_TYPE_WRBACK]         = "WB",
+        [MTRR_NUM_TYPES]           = "??"
+    };
+
+    return x < ARRAY_SIZE(memory_types) ? (memory_types[x] ?: "?") : "?";
+}
+
 static void ept_dump_p2m_table(unsigned char key)
 {
     struct domain *d;
@@ -1212,15 +1226,6 @@ static void ept_dump_p2m_table(unsigned char key)
     unsigned long record_counter = 0;
     struct p2m_domain *p2m;
     struct ept_data *ept;
-    static const char memory_types[8][2] = {
-        [0 ... 7] = "?",
-        [MTRR_TYPE_UNCACHABLE]     = "UC",
-        [MTRR_TYPE_WRCOMB]         = "WC",
-        [MTRR_TYPE_WRTHROUGH]      = "WT",
-        [MTRR_TYPE_WRPROT]         = "WP",
-        [MTRR_TYPE_WRBACK]         = "WB",
-        [MTRR_NUM_TYPES]           = "??"
-    };
 
     for_each_domain(d)
     {
@@ -1260,8 +1265,8 @@ static void ept_dump_p2m_table(unsigned char key)
                            ept_entry->r ? 'r' : ' ',
                            ept_entry->w ? 'w' : ' ',
                            ept_entry->x ? 'x' : ' ',
-                           memory_types[ept_entry->emt][0],
-                           memory_types[ept_entry->emt][1]
+                           memory_type_to_str(ept_entry->emt)[0],
+                           memory_type_to_str(ept_entry->emt)[1]
                            ?: ept_entry->emt + '0',
                            c ?: ept_entry->ipat ? '!' : ' ');