mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
x86: fix errors arising from c/s dab76ff
Coverity correctly identifies that the changes in mtrr_attrib_to_str() introduce dead code. strings[] is a 2d array, rather than an array of strings, which means that strings[x] will never be a NULL pointer. Adjust the check to compenstate, by looking for a NUL in strings[x][0] instead. Curiously, Coverity did not notice the same error with memory_type_to_str(). There was also a further error; the strings were not NULL terminated, which made the return type of memory_type_to_str() erronious. Bump the 2D array to 3 characters, so the strings retain their NUL characters, and introduce an ASSERT() as requested on one thread of the original patch. Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
This commit is contained in:
1 parent
0359b365c6
commit
fb0e5fea8a
2 files changed
+4
-3
No files matched your search
@@ -98,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 < ARRAY_SIZE(strings) && strings[x][0]) ? strings[x] : "?";
|
||||
}
|
||||
|
||||
static unsigned int __initdata last_fixed_start;
|
||||
|
||||
@@ -1204,7 +1204,7 @@ void ept_p2m_uninit(struct p2m_domain *p2m)
|
||||
|
||||
static const char *memory_type_to_str(unsigned int x)
|
||||
{
|
||||
static const char memory_types[8][2] = {
|
||||
static const char memory_types[8][3] = {
|
||||
[MTRR_TYPE_UNCACHABLE] = "UC",
|
||||
[MTRR_TYPE_WRCOMB] = "WC",
|
||||
[MTRR_TYPE_WRTHROUGH] = "WT",
|
||||
@@ -1213,7 +1213,8 @@ static const char *memory_type_to_str(unsigned int x)
|
||||
[MTRR_NUM_TYPES] = "??"
|
||||
};
|
||||
|
||||
return x < ARRAY_SIZE(memory_types) ? (memory_types[x] ?: "?") : "?";
|
||||
ASSERT(x < ARRAY_SIZE(memory_types));
|
||||
return memory_types[x][0] ? memory_types[x] : "?";
|
||||
}
|
||||
|
||||
static void ept_dump_p2m_table(unsigned char key)
|
||||
|
||||