From patchwork Tue Feb 9 20:01:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 8265451 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 BBA349F38B for ; Tue, 9 Feb 2016 20:04:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E2857201BC for ; Tue, 9 Feb 2016 20:04:45 +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 0851A2022D for ; Tue, 9 Feb 2016 20:04:45 +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 1aTEU2-0001dN-JP; Tue, 09 Feb 2016 20:01:58 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aTETz-0001cA-R1 for xen-devel@lists.xen.org; Tue, 09 Feb 2016 20:01:55 +0000 Received: from [85.158.137.68] by server-12.bemta-3.messagelabs.com id F7/43-06010-3B54AB65; Tue, 09 Feb 2016 20:01:55 +0000 X-Env-Sender: prvs=8403a2554=Andrew.Cooper3@citrix.com X-Msg-Ref: server-5.tower-31.messagelabs.com!1455048112!21355650!2 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 45729 invoked from network); 9 Feb 2016 20:01:54 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-5.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 9 Feb 2016 20:01:54 -0000 X-IronPort-AV: E=Sophos;i="5.22,422,1449532800"; d="scan'208";a="330665319" From: Andrew Cooper To: Xen-devel Date: Tue, 9 Feb 2016 20:01:46 +0000 Message-ID: <1455048108-5045-7-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1455048108-5045-1-git-send-email-andrew.cooper3@citrix.com> References: <1455048108-5045-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: George Dunlap , Andrew Cooper , Kevin Tian , Jun Nakajima , Jan Beulich Subject: [Xen-devel] [PATCH 6/8] xen/x86: Avoid overriding initialisers in arrays 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 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 Acked-by: George Dunlap Acked-by: Kevin Tian --- CC: Jan Beulich CC: George Dunlap CC: Jun Nakajima CC: Kevin Tian --- xen/arch/x86/cpu/mtrr/generic.c | 3 +-- xen/arch/x86/mm/p2m-ept.c | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/xen/arch/x86/cpu/mtrr/generic.c b/xen/arch/x86/cpu/mtrr/generic.c index ea0efe2..8839f8d 100644 --- a/xen/arch/x86/cpu/mtrr/generic.c +++ b/xen/arch/x86/cpu/mtrr/generic.c @@ -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; diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c index c094320..c5fe906 100644 --- a/xen/arch/x86/mm/p2m-ept.c +++ b/xen/arch/x86/mm/p2m-ept.c @@ -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 ? '!' : ' ');