diff mbox series

[XEN,2/6] libelf: address MISRA C:2012 Rule 5.3

Message ID 55624244c42297da7da954009ba0559c47fc245e.1691162261.git.nicola.vetrini@bugseng.com (mailing list archive)
State Superseded
Headers show
Series xen: address MISRA C:2012 Rule 5.3 | expand

Commit Message

Nicola Vetrini Aug. 4, 2023, 3:27 p.m. UTC
The types u{8,16,32,64} defined in 'xen/arch/x86/include/asm/types.h'
shadow the variables in the modified function, hence violating Rule 5.3.
Therefore, the rename takes care of the shadowing.

No functional changes.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
---
 xen/common/libelf/libelf-tools.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

Comments

Stefano Stabellini Aug. 4, 2023, 9:21 p.m. UTC | #1
On Fri, 4 Aug 2023, Nicola Vetrini wrote:
> The types u{8,16,32,64} defined in 'xen/arch/x86/include/asm/types.h'
> shadow the variables in the modified function, hence violating Rule 5.3.
> Therefore, the rename takes care of the shadowing.
> 
> No functional changes.
> 
> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


> ---
>  xen/common/libelf/libelf-tools.c | 24 ++++++++++++------------
>  1 file changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/xen/common/libelf/libelf-tools.c b/xen/common/libelf/libelf-tools.c
> index a9edb6a8dc..f0d5da1abf 100644
> --- a/xen/common/libelf/libelf-tools.c
> +++ b/xen/common/libelf/libelf-tools.c
> @@ -91,10 +91,10 @@ uint64_t elf_access_unsigned(struct elf_binary * elf, elf_ptrval base,
>  {
>      elf_ptrval ptrval = base + moreoffset;
>      bool need_swap = elf_swap(elf);
> -    const uint8_t *u8;
> -    const uint16_t *u16;
> -    const uint32_t *u32;
> -    const uint64_t *u64;
> +    const uint8_t *uint8;
> +    const uint16_t *uint16;
> +    const uint32_t *uint32;
> +    const uint64_t *uint64;
>  
>      if ( !elf_access_ok(elf, ptrval, size) )
>          return 0;
> @@ -102,17 +102,17 @@ uint64_t elf_access_unsigned(struct elf_binary * elf, elf_ptrval base,
>      switch ( size )
>      {
>      case 1:
> -        u8 = (const void*)ptrval;
> -        return *u8;
> +        uint8 = (const void*)ptrval;
> +        return *uint8;
>      case 2:
> -        u16 = (const void*)ptrval;
> -        return need_swap ? bswap_16(*u16) : *u16;
> +        uint16 = (const void*)ptrval;
> +        return need_swap ? bswap_16(*uint16) : *uint16;
>      case 4:
> -        u32 = (const void*)ptrval;
> -        return need_swap ? bswap_32(*u32) : *u32;
> +        uint32 = (const void*)ptrval;
> +        return need_swap ? bswap_32(*uint32) : *uint32;
>      case 8:
> -        u64 = (const void*)ptrval;
> -        return need_swap ? bswap_64(*u64) : *u64;
> +        uint64 = (const void*)ptrval;
> +        return need_swap ? bswap_64(*uint64) : *uint64;
>      default:
>          return 0;
>      }
> -- 
> 2.34.1
>
Jan Beulich Aug. 7, 2023, 8:11 a.m. UTC | #2
On 04.08.2023 17:27, Nicola Vetrini wrote:
> The types u{8,16,32,64} defined in 'xen/arch/x86/include/asm/types.h'
> shadow the variables in the modified function, hence violating Rule 5.3.
> Therefore, the rename takes care of the shadowing.
> 
> No functional changes.
> 
> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
> ---
>  xen/common/libelf/libelf-tools.c | 24 ++++++++++++------------
>  1 file changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/xen/common/libelf/libelf-tools.c b/xen/common/libelf/libelf-tools.c
> index a9edb6a8dc..f0d5da1abf 100644
> --- a/xen/common/libelf/libelf-tools.c
> +++ b/xen/common/libelf/libelf-tools.c
> @@ -91,10 +91,10 @@ uint64_t elf_access_unsigned(struct elf_binary * elf, elf_ptrval base,
>  {
>      elf_ptrval ptrval = base + moreoffset;
>      bool need_swap = elf_swap(elf);
> -    const uint8_t *u8;
> -    const uint16_t *u16;
> -    const uint32_t *u32;
> -    const uint64_t *u64;
> +    const uint8_t *uint8;
> +    const uint16_t *uint16;
> +    const uint32_t *uint32;
> +    const uint64_t *uint64;

While the chosen names won't collide with stdint.h's, I still consider
them odd. These all being pointers, why not simply pu<N> as names?

Jan
Nicola Vetrini Aug. 7, 2023, 9:03 a.m. UTC | #3
On 07/08/2023 10:11, Jan Beulich wrote:
> On 04.08.2023 17:27, Nicola Vetrini wrote:
>> The types u{8,16,32,64} defined in 'xen/arch/x86/include/asm/types.h'
>> shadow the variables in the modified function, hence violating Rule 
>> 5.3.
>> Therefore, the rename takes care of the shadowing.
>> 
>> No functional changes.
>> 
>> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
>> ---
>>  xen/common/libelf/libelf-tools.c | 24 ++++++++++++------------
>>  1 file changed, 12 insertions(+), 12 deletions(-)
>> 
>> diff --git a/xen/common/libelf/libelf-tools.c 
>> b/xen/common/libelf/libelf-tools.c
>> index a9edb6a8dc..f0d5da1abf 100644
>> --- a/xen/common/libelf/libelf-tools.c
>> +++ b/xen/common/libelf/libelf-tools.c
>> @@ -91,10 +91,10 @@ uint64_t elf_access_unsigned(struct elf_binary * 
>> elf, elf_ptrval base,
>>  {
>>      elf_ptrval ptrval = base + moreoffset;
>>      bool need_swap = elf_swap(elf);
>> -    const uint8_t *u8;
>> -    const uint16_t *u16;
>> -    const uint32_t *u32;
>> -    const uint64_t *u64;
>> +    const uint8_t *uint8;
>> +    const uint16_t *uint16;
>> +    const uint32_t *uint32;
>> +    const uint64_t *uint64;
> 
> While the chosen names won't collide with stdint.h's, I still consider
> them odd. These all being pointers, why not simply pu<N> as names?
> 
> Jan

lgtm.
diff mbox series

Patch

diff --git a/xen/common/libelf/libelf-tools.c b/xen/common/libelf/libelf-tools.c
index a9edb6a8dc..f0d5da1abf 100644
--- a/xen/common/libelf/libelf-tools.c
+++ b/xen/common/libelf/libelf-tools.c
@@ -91,10 +91,10 @@  uint64_t elf_access_unsigned(struct elf_binary * elf, elf_ptrval base,
 {
     elf_ptrval ptrval = base + moreoffset;
     bool need_swap = elf_swap(elf);
-    const uint8_t *u8;
-    const uint16_t *u16;
-    const uint32_t *u32;
-    const uint64_t *u64;
+    const uint8_t *uint8;
+    const uint16_t *uint16;
+    const uint32_t *uint32;
+    const uint64_t *uint64;
 
     if ( !elf_access_ok(elf, ptrval, size) )
         return 0;
@@ -102,17 +102,17 @@  uint64_t elf_access_unsigned(struct elf_binary * elf, elf_ptrval base,
     switch ( size )
     {
     case 1:
-        u8 = (const void*)ptrval;
-        return *u8;
+        uint8 = (const void*)ptrval;
+        return *uint8;
     case 2:
-        u16 = (const void*)ptrval;
-        return need_swap ? bswap_16(*u16) : *u16;
+        uint16 = (const void*)ptrval;
+        return need_swap ? bswap_16(*uint16) : *uint16;
     case 4:
-        u32 = (const void*)ptrval;
-        return need_swap ? bswap_32(*u32) : *u32;
+        uint32 = (const void*)ptrval;
+        return need_swap ? bswap_32(*uint32) : *uint32;
     case 8:
-        u64 = (const void*)ptrval;
-        return need_swap ? bswap_64(*u64) : *u64;
+        uint64 = (const void*)ptrval;
+        return need_swap ? bswap_64(*uint64) : *uint64;
     default:
         return 0;
     }