From patchwork Fri Feb 12 14:59:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 8292551 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6EE879F6E4 for ; Fri, 12 Feb 2016 15:02:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8F241203EB for ; Fri, 12 Feb 2016 15:02:49 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 95CA5201C7 for ; Fri, 12 Feb 2016 15:02:47 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aUFCM-0002iZ-Te; Fri, 12 Feb 2016 14:59:54 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aUFCL-0002hf-LC for xen-devel@lists.xen.org; Fri, 12 Feb 2016 14:59:53 +0000 Received: from [85.158.137.68] by server-6.bemta-3.messagelabs.com id 8A/E5-08479-863FDB65; Fri, 12 Feb 2016 14:59:52 +0000 X-Env-Sender: prvs=843bae1bd=Andrew.Cooper3@citrix.com X-Msg-Ref: server-14.tower-31.messagelabs.com!1455289191!22026029!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 61349 invoked from network); 12 Feb 2016 14:59:52 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-14.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 12 Feb 2016 14:59:52 -0000 X-IronPort-AV: E=Sophos;i="5.22,436,1449532800"; d="scan'208";a="337841863" From: Andrew Cooper To: Xen-devel Date: Fri, 12 Feb 2016 14:59:49 +0000 Message-ID: <1455289189-32425-1-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 X-DLP: MIA2 Cc: George Dunlap , Andrew Cooper , Jan Beulich Subject: [Xen-devel] [PATCH] xen/x86: Fix errors arising from c/s dab76ff X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- CC: Jan Beulich CC: George Dunlap --- 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)