[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [XEN PATCH 1/6] x86: rename variable 'e820' to address MISRA C:2012 Rule 5.3


  • To: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 8 Aug 2023 09:21:26 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Jpm7zzJKhEBlzZOTLSH5wysuwemJIRZ5GAovXG2lyus=; b=ZFyD1XTTEGKjwDY/bittyeSJq1J6xyRyQUgQA0/wva2qUTxLygNpZmannFVU2fMZg+UQcdmbpAF723Ff2k2Kywe/46Z0UsFzN0H9xnrmQiDIQOhi66NcUbM1HC/uSKFt5chMA8PoC+ups9+D7LOgEty0vQ1UvkFx78V6NTIqyITF96UR3rfu6wAzA/MC0vtwJH9jMPXb5/nF3wmcag/b8QrNzJ1K17UzrEXNlI+daFRfygZsllcgRLeCcjAcmafdklbzAMdWWoXCz9duMZ9fVGXP2k3b5mCs8ISPhLVrSXnxtcJ7QSqb7LImHXSNcmA0vxaBzzMx84NxDKhvFchOLg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jYcyGT6CiDUyxag7eSOL8Ie6m1wsdZKFjAIcOQSr0WZTUxGj5cTaMCvvy2hH4cFGdLC5HbYOxC60P/7VCrcLvX4JnMf+BzproeaH5xYU6Q8CeYqLlmjCAp4bphGJbBXG50tuWbw1PDQnAzBXutBqydHXaJdizbWQ6wBFB2CMHEeItDT7zALKFErVue6aoUQPTa/WBhxdprhW3VtM0v6phRAUOblyVs8rJv52yPTWuzsA+W5wssJeIxNscj+xB4ED/zsfaNT++9aBrYFn1VfYNs5zu3Yyaaj0Kk4dg1Xpc9S1LU1Q8Kctybd29NZoSUdFpvnhHcLB8mU+aRAV3Gel7Q==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: sstabellini@xxxxxxxxxx, michal.orzel@xxxxxxx, xenia.ragiadakou@xxxxxxx, ayan.kumar.halder@xxxxxxx, consulting@xxxxxxxxxxx, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Tue, 08 Aug 2023 07:22:09 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 08.08.2023 09:08, Nicola Vetrini wrote:
> On 07/08/2023 11:10, Jan Beulich wrote:
>> On 07.08.2023 10:59, Nicola Vetrini wrote:
>>> On 07/08/2023 10:09, Jan Beulich wrote:
>>>> On 04.08.2023 17:27, Nicola Vetrini wrote:
>>>>> The variable declared in the header file
>>>>> 'xen/arch/x86/include/asm/e820.h'
>>>>> is shadowed by many function parameters, so it is renamed to avoid
>>>>> these
>>>>> violations.
>>>>>
>>>>> No functional changes.
>>>>>
>>>>> Signed-off-by: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
>>>>> ---
>>>>> This patch is similar to other renames done on previous patches, and
>>>>> the
>>>>> preferred strategy there was to rename the global variable. This one
>>>>> has more occurrences that are spread in various files, but
>>>>> the general pattern is the same.
>>>>
>>>> Still I think it would be better done the other way around, and 
>>>> perhaps
>>>> in
>>>> more than a single patch. It looks like "many == 3", i.e.
>>>> - e820_add_range(), which is only ever called with "e820" as its
>>>> argument,
>>>>   and hence the parameter could be dropped,
> 
> I see another downside with this approach (I should have spotted this 
> sooner):
> Since e820_add_range and the other functions expected e820 as a pointer, 
> they are
> written like this:
> 
> for ( i = 0; i < e820->nr_map; ++i )
>      {
>          uint64_t rs = e820->map[i].addr;
>          uint64_t re = rs + e820->map[i].size;
> 
>          if ( rs == e && e820->map[i].type == type )
>          {
>              e820->map[i].addr = s;
>              return 1;
>          }
> ...
> 
> Dropping the parameter would either mean
> 1. Use a local parameter that stores the address of e820, which kind of
>     nullifies the purpose of dropping the parameter imho;

This isn't an unusual thing to do; it is only the name being short which
may make it look "unnecessary" here. But especially if the local variable
was made of type struct e820entry * (and updated in the for()) I think
this could be useful overall.

> 2. Rewrite it so that it operates on a "struct e820map", which would 
> mean
>     substantial churn;
> 3. Make the global a pointer, which is reminiscent of (1)
> 
> All in all, I do like the global renaming approach more, because it 
> lessens
> the amount of code that needs to change to accomodate a case of 
> shadowing.

Well, to go that route you need to come up with a suitable new name (no
prior proposal was really meeting that requirement) and you'd need to
convince at least one of the x86 maintainers.

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.