diff mbox series

[5/5] xen/arm: address violations of MISRA C:2012 Rule 11.8

Message ID df2af5f9a93c3cbcb61c28ff5228632c82d56f37.1700842832.git.maria.celeste.cesario@bugseng.com (mailing list archive)
State Superseded
Headers show
Series xen: address violations of MISRA C:2012 Rule 11.8 | expand

Commit Message

Simone Ballarin Nov. 24, 2023, 4:29 p.m. UTC
From: Maria Celeste Cesario <maria.celeste.cesario@bugseng.com>

Add or amend casts to comply with Rule 11.8.

The violations are resolved either:
- by adding a missing const qualifier in the cast
- by removing a cast to non-const on a const-qualified object

No functional change.

Signed-off-by: Maria Celeste Cesario  <maria.celeste.cesario@bugseng.com>
Signed-off-by: Simone Ballarin  <simone.ballarin@bugseng.com>
---
 xen/arch/arm/domain_build.c       | 2 +-
 xen/arch/arm/include/asm/atomic.h | 2 +-
 xen/arch/arm/include/asm/regs.h   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

Comments

Julien Grall Nov. 29, 2023, 5:50 p.m. UTC | #1
Hi,

On 24/11/2023 17:29, Simone Ballarin wrote:
> From: Maria Celeste Cesario <maria.celeste.cesario@bugseng.com>
> 
> Add or amend casts to comply with Rule 11.8.
> 
> The violations are resolved either:
> - by adding a missing const qualifier in the cast
> - by removing a cast to non-const on a const-qualified object
> 
> No functional change.
> 
> Signed-off-by: Maria Celeste Cesario  <maria.celeste.cesario@bugseng.com>
> Signed-off-by: Simone Ballarin  <simone.ballarin@bugseng.com>
> ---
>   xen/arch/arm/domain_build.c       | 2 +-
>   xen/arch/arm/include/asm/atomic.h | 2 +-
>   xen/arch/arm/include/asm/regs.h   | 2 +-
>   3 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
> index 2dd2926b41..c17214f738 100644
> --- a/xen/arch/arm/domain_build.c
> +++ b/xen/arch/arm/domain_build.c
> @@ -2749,7 +2749,7 @@ static int __init handle_passthrough_prop(struct kernel_info *kinfo,
>       if ( node == NULL )
>       {
>           printk(XENLOG_ERR "Couldn't find node %s in host_dt!\n",
> -               (char *)xen_path->data);
> +               xen_path->data);

I am a little bit puzzled why the cast was originally added here. 
Stefano, do you remember?

Also, this hunk will not apply on staging (the code has moved to 
dom0less-build.c). This will want a new version.

>           return -EINVAL;
>       }
>   
> diff --git a/xen/arch/arm/include/asm/atomic.h b/xen/arch/arm/include/asm/atomic.h
> index 64314d59b3..517216d2a8 100644
> --- a/xen/arch/arm/include/asm/atomic.h
> +++ b/xen/arch/arm/include/asm/atomic.h
> @@ -154,7 +154,7 @@ static always_inline void write_atomic_size(volatile void *p,
>    */
>   static inline int atomic_read(const atomic_t *v)
>   {
> -    return *(volatile int *)&v->counter;
> +    return *(const volatile int *)&v->counter;
>   }
>   
>   static inline int _atomic_read(atomic_t v)
> diff --git a/xen/arch/arm/include/asm/regs.h b/xen/arch/arm/include/asm/regs.h
> index 8a0db95415..79050937f3 100644
> --- a/xen/arch/arm/include/asm/regs.h
> +++ b/xen/arch/arm/include/asm/regs.h
> @@ -48,7 +48,7 @@ static inline bool regs_mode_is_32bit(const struct cpu_user_regs *regs)
>   
>   static inline bool guest_mode(const struct cpu_user_regs *r)
>   {
> -    unsigned long diff = (char *)guest_cpu_user_regs() - (char *)(r);
> +    unsigned long diff = (char *)guest_cpu_user_regs() - (const char *)(r);

NIT: I would take the opportunity to use 'const char*' for the first one 
as well.

>       /* Frame pointer must point into current CPU stack. */
>       ASSERT(diff < STACK_SIZE);
>       /* If not a guest frame, it must be a hypervisor frame. */

Cheers,
Jan Beulich Nov. 30, 2023, 8:45 a.m. UTC | #2
On 29.11.2023 18:50, Julien Grall wrote:
> On 24/11/2023 17:29, Simone Ballarin wrote:
>> --- a/xen/arch/arm/include/asm/regs.h
>> +++ b/xen/arch/arm/include/asm/regs.h
>> @@ -48,7 +48,7 @@ static inline bool regs_mode_is_32bit(const struct cpu_user_regs *regs)
>>   
>>   static inline bool guest_mode(const struct cpu_user_regs *r)
>>   {
>> -    unsigned long diff = (char *)guest_cpu_user_regs() - (char *)(r);
>> +    unsigned long diff = (char *)guest_cpu_user_regs() - (const char *)(r);
> 
> NIT: I would take the opportunity to use 'const char*' for the first one 
> as well.

Considering a similar change likely is being (or is to be) done on x86,
I'd favor not abusing "char *" here. Either use "void *", or - considering
the intended result type - go straight to "unsigned long" (or uintptr_t).
I would certainly ask for that on the x86 side.

Jan
diff mbox series

Patch

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 2dd2926b41..c17214f738 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -2749,7 +2749,7 @@  static int __init handle_passthrough_prop(struct kernel_info *kinfo,
     if ( node == NULL )
     {
         printk(XENLOG_ERR "Couldn't find node %s in host_dt!\n",
-               (char *)xen_path->data);
+               xen_path->data);
         return -EINVAL;
     }
 
diff --git a/xen/arch/arm/include/asm/atomic.h b/xen/arch/arm/include/asm/atomic.h
index 64314d59b3..517216d2a8 100644
--- a/xen/arch/arm/include/asm/atomic.h
+++ b/xen/arch/arm/include/asm/atomic.h
@@ -154,7 +154,7 @@  static always_inline void write_atomic_size(volatile void *p,
  */
 static inline int atomic_read(const atomic_t *v)
 {
-    return *(volatile int *)&v->counter;
+    return *(const volatile int *)&v->counter;
 }
 
 static inline int _atomic_read(atomic_t v)
diff --git a/xen/arch/arm/include/asm/regs.h b/xen/arch/arm/include/asm/regs.h
index 8a0db95415..79050937f3 100644
--- a/xen/arch/arm/include/asm/regs.h
+++ b/xen/arch/arm/include/asm/regs.h
@@ -48,7 +48,7 @@  static inline bool regs_mode_is_32bit(const struct cpu_user_regs *regs)
 
 static inline bool guest_mode(const struct cpu_user_regs *r)
 {
-    unsigned long diff = (char *)guest_cpu_user_regs() - (char *)(r);
+    unsigned long diff = (char *)guest_cpu_user_regs() - (const char *)(r);
     /* Frame pointer must point into current CPU stack. */
     ASSERT(diff < STACK_SIZE);
     /* If not a guest frame, it must be a hypervisor frame. */