xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: George Dunlap <george.dunlap@eu.citrix.com>,
	Kevin Tian <kevin.tian@intel.com>,
	JunNakajima <jun.nakajima@intel.com>,
	Xen-devel <xen-devel@lists.xen.org>
Subject: Re: [PATCH 6/8] xen/x86: Avoid overriding initialisers in arrays
Date: Wed, 10 Feb 2016 13:50:58 +0000	[thread overview]
Message-ID: <56BB4042.70409@citrix.com> (raw)
In-Reply-To: <56BB47BF02000078000D08FC@prv-mh.provo.novell.com>

On 10/02/16 13:22, Jan Beulich wrote:
>>>> On 09.02.16 at 21:01, <andrew.cooper3@citrix.com> wrote:
>> 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.
> Ugly again, but - well ...
>
>> --- 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] ?: "?") : "?";
> I think this should really ASSERT() the first condition.
>
>> @@ -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 ? '!' : ' ');
> There's actually a bug here, which I think is worth fixing at once:
> The default initializer was a string of length 1, resulting in a
> premature NUL character to get placed into the fully expanded
> string, causing - afaict - truncation of the intended message. I
> therefore think the default string should be e.g. "? ".

The code is very opaque.  However, that appears to be precisely how it
is intended to work.  (Having said that - it is your code from c/s
90e9c95f).

The following line will only format the raw emt value as a number if
there is a NUL character returned from memory_type_to_str().  Putting a
space in instead would break this.

~Andrew

  reply	other threads:[~2016-02-10 13:50 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-09 20:01 [PATCH 0/8] xen/x86: Fix build with Clang 3.5 Andrew Cooper
2016-02-09 20:01 ` [PATCH 1/8] xen/lib: Fix ASSERT() to build with clang Andrew Cooper
2016-02-09 20:01 ` [PATCH 2/8] xen/misc: Remove or annotate possibly-unused functions Andrew Cooper
2016-02-10 10:42   ` Tim Deegan
2016-02-10 13:06   ` Jan Beulich
2016-02-10 13:15     ` Andrew Cooper
2016-02-09 20:01 ` [PATCH 3/8] xen/x86: Remove %z modifier from inline assembly Andrew Cooper
2016-02-10 13:10   ` Jan Beulich
2016-02-09 20:01 ` [PATCH 4/8] xen/x86: Fix section type mismatch in mm.c Andrew Cooper
2016-02-10 10:01   ` George Dunlap
2016-02-09 20:01 ` [PATCH 5/8] xen/x86: Improve annotation of autogen_entrypoints[] Andrew Cooper
2016-02-09 20:01 ` [PATCH 6/8] xen/x86: Avoid overriding initialisers in arrays Andrew Cooper
2016-02-10 10:11   ` George Dunlap
2016-02-10 13:22   ` Jan Beulich
2016-02-10 13:50     ` Andrew Cooper [this message]
2016-02-10 14:03       ` Jan Beulich
2016-02-10 14:13         ` George Dunlap
2016-02-16  7:06   ` Tian, Kevin
2016-02-09 20:01 ` [PATCH 7/8] xen/x86: Fix get_cpu_info() when built with clang Andrew Cooper
2016-02-09 20:01 ` [PATCH 8/8] x86/efi: Generate uefi_call_wrapper() when compiling " Andrew Cooper
2016-02-10 13:31   ` Jan Beulich
2016-02-10 13:41     ` Andrew Cooper
2016-02-10 19:11       ` Andrew Cooper
2016-02-11 10:45         ` Jan Beulich
2016-02-09 21:09 ` [PATCH 0/8] xen/x86: Fix build with Clang 3.5 Doug Goldstein
2016-02-10  9:28 ` Ian Campbell

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=56BB4042.70409@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=george.dunlap@eu.citrix.com \
    --cc=jun.nakajima@intel.com \
    --cc=kevin.tian@intel.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).