From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: George Dunlap <george.dunlap@eu.citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Jan Beulich <JBeulich@suse.com>
Subject: [PATCH] xen/x86: Fix errors arising from c/s dab76ff
Date: Fri, 12 Feb 2016 14:59:49 +0000 [thread overview]
Message-ID: <1455289189-32425-1-git-send-email-andrew.cooper3@citrix.com> (raw)
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>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: George Dunlap <george.dunlap@eu.citrix.com>
---
xen/arch/x86/cpu/mtrr/generic.c | 2 +-
xen/arch/x86/mm/p2m-ept.c | 5 +++--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/xen/arch/x86/cpu/mtrr/generic.c b/xen/arch/x86/cpu/mtrr/generic.c
index 8839f8d..234d2ba 100644
--- a/xen/arch/x86/cpu/mtrr/generic.c
+++ b/xen/arch/x86/cpu/mtrr/generic.c
@@ -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;
diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c
index 316e3f3..3cb6868 100644
--- a/xen/arch/x86/mm/p2m-ept.c
+++ b/xen/arch/x86/mm/p2m-ept.c
@@ -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)
--
2.1.4
next reply other threads:[~2016-02-12 14:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-12 14:59 Andrew Cooper [this message]
2016-02-12 15:13 ` [PATCH] xen/x86: Fix errors arising from c/s dab76ff Jan Beulich
2016-02-12 15:23 ` Andrew Cooper
2016-02-15 15:15 ` George Dunlap
2016-02-15 16:52 ` Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1455289189-32425-1-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.com \
--cc=george.dunlap@eu.citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).