Skip to contentSkip to conversation

x86: Address MISRA Rule 13.6

PATCH In review Andrew Cooper 3 participants 7 messages Apr 2, 2024 – Apr 3, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: Address MISRA Rule 13.6

MISRA Rule 13.6 doesn't like having an expression in a sizeof() which potentially has side effects.

Address several violations by pulling the expression out into a local variable.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Roberto Bagnara <[email protected]>
CC: [email protected] <[email protected]>

Slightly RFC.

---
 xen/arch/x86/irq.c                       | 3 ++-
 xen/arch/x86/time.c                      | 6 ++++--
 xen/drivers/passthrough/amd/iommu_intr.c | 3 ++-
 3 files changed, 8 insertions(+), 4 deletions(-)
xen/arch/x86/irq.c +2 -1
index 0487f734a5d2..d73f687f7617 100644
@@ -1150,8 +1150,9 @@ static void cf_check irq_guest_eoi_timer_fn(void *data)
     {
         struct domain *d = action->guest[i];
         unsigned int pirq = domain_irq_to_pirq(d, irq);
+        struct pirq *pirq_info = pirq_info(d, pirq);
 
-        if ( test_and_clear_bool(pirq_info(d, pirq)->masked) )
+        if ( test_and_clear_bool(pirq_info->masked) )
             action->in_flight--;
     }
 
xen/arch/x86/time.c +4 -2
index 60870047894b..6f136f4b14bf 100644
@@ -2503,7 +2503,9 @@ static long cmos_utc_offset; /* in seconds */
 
 int time_suspend(void)
 {
-    if ( smp_processor_id() == 0 )
+    unsigned int cpu = smp_processor_id();
+
+    if ( cpu == 0 )
     {
         cmos_utc_offset = -get_wallclock_time();
         cmos_utc_offset += get_sec();
@@ -2514,7 +2516,7 @@ int time_suspend(void)
     }
 
     /* Better to cancel calibration timer for accuracy. */
-    clear_bit(TIME_CALIBRATE_SOFTIRQ, &softirq_pending(smp_processor_id()));
+    clear_bit(TIME_CALIBRATE_SOFTIRQ, &softirq_pending(cpu));
 
     return 0;
 }
xen/drivers/passthrough/amd/iommu_intr.c +2 -1
index d9eefcd8e411..7fc796dec25b 100644
@@ -183,6 +183,7 @@ static void free_intremap_entry(const struct amd_iommu *iommu,
                                 unsigned int bdf, unsigned int index)
 {
     union irte_ptr entry = get_intremap_entry(iommu, bdf, index);
+    struct ivrs_mappings *ivrs = get_ivrs_mappings(iommu->seg);
 
     if ( iommu->ctrl.ga_en )
     {
@@ -201,7 +202,7 @@ static void free_intremap_entry(const struct amd_iommu *iommu,
     else
         ACCESS_ONCE(entry.ptr32->raw) = 0;
 
-    __clear_bit(index, get_ivrs_mappings(iommu->seg)[bdf].intremap_inuse);
+    __clear_bit(index, ivrs[bdf].intremap_inuse);
 }
 
 static void update_intremap_entry(const struct amd_iommu *iommu,

base-commit: 7a09966e7b2823b70f6d56d0cf66c11124f4a3c1

Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Andrew Cooper

MISRA Rule 13.6 doesn't like having an expression in a sizeof() which potentially has side effects.

Address several violations by pulling the expression out into a local variable.

No functional change.

with one caveat:

xen/arch/x86/irq.c static void cf_check irq_guest_eoi_timer_fn(void *data) · line 1153

Quoted 7 lines
xen/arch/x86/irq.c +1 -0
@@ -1150,8 +1150,9 @@ static void cf_check irq_guest_eoi_timer_fn(void *data)
     {
         struct domain *d = action->guest[i];
         unsigned int pirq = domain_irq_to_pirq(d, irq);
+        struct pirq *pirq_info = pirq_info(d, pirq);

Misra won't like the var's name matching the macro's. Can we go with just "info"?

Jan

#2 lore raw
Quoted 13 lines · Jan Beulich
Quoted 9 lines · Andrew Cooper

MISRA Rule 13.6 doesn't like having an expression in a sizeof() which potentially has side effects.

Address several violations by pulling the expression out into a local variable.

No functional change.

with one caveat:

Quoted 9 lines

xen/arch/x86/irq.c static void cf_check irq_guest_eoi_timer_fn(void *data) · line 1153

Quoted 7 lines
xen/arch/x86/irq.c +1 -0
@@ -1150,8 +1150,9 @@ static void cf_check irq_guest_eoi_timer_fn(void *data)
     {
         struct domain *d = action->guest[i];
         unsigned int pirq = domain_irq_to_pirq(d, irq);
+        struct pirq *pirq_info = pirq_info(d, pirq);

Misra won't like the var's name matching the macro's. Can we go with just "info"?

Ah - missed that.

I can name it to just info, but I considered "struct pirq *info" to be a little odd.

~Andrew

#3 lore raw
Quoted 24 lines · Andrew Cooper
Quoted 13 lines · Jan Beulich
Quoted 9 lines · Andrew Cooper

MISRA Rule 13.6 doesn't like having an expression in a sizeof() which potentially has side effects.

Address several violations by pulling the expression out into a local variable.

No functional change.

with one caveat:

Quoted 9 lines

xen/arch/x86/irq.c static void cf_check irq_guest_eoi_timer_fn(void *data) · line 1153

Quoted 7 lines
xen/arch/x86/irq.c +1 -0
@@ -1150,8 +1150,9 @@ static void cf_check irq_guest_eoi_timer_fn(void *data)
     {
         struct domain *d = action->guest[i];
         unsigned int pirq = domain_irq_to_pirq(d, irq);
+        struct pirq *pirq_info = pirq_info(d, pirq);

Misra won't like the var's name matching the macro's. Can we go with just "info"?

Quoted 4 lines

Ah - missed that.

I can name it to just info, but I considered "struct pirq *info" to be a little odd.

I agree, but what do you do with another "pirq" already there.

Or wait, what about

        struct pirq *pirq = pirq_info(d, domain_irq_to_pirq(d, irq));

?

Jan

#4 lore raw
Quoted 28 lines · Jan Beulich
Quoted 23 lines · Andrew Cooper
Quoted 13 lines · Jan Beulich
Quoted 9 lines · Andrew Cooper

MISRA Rule 13.6 doesn't like having an expression in a sizeof() which potentially has side effects.

Address several violations by pulling the expression out into a local variable.

No functional change.

with one caveat:

Quoted 9 lines

xen/arch/x86/irq.c static void cf_check irq_guest_eoi_timer_fn(void *data) · line 1153

Quoted 7 lines
xen/arch/x86/irq.c +1 -0
@@ -1150,8 +1150,9 @@ static void cf_check irq_guest_eoi_timer_fn(void *data)
     {
         struct domain *d = action->guest[i];
         unsigned int pirq = domain_irq_to_pirq(d, irq);
+        struct pirq *pirq_info = pirq_info(d, pirq);

Misra won't like the var's name matching the macro's. Can we go with just "info"?

Quoted 4 lines

Ah - missed that.

I can name it to just info, but I considered "struct pirq *info" to be a little odd.

Quoted 7 lines

I agree, but what do you do with another "pirq" already there.

Or wait, what about

        struct pirq *pirq = pirq_info(d, domain_irq_to_pirq(d, irq));

?

That should work.  I'll switch to this locally, and wait for the feedback on whether the patch works for 13.6.

~Andrew

#5 lore raw
Quoted 31 lines · Andrew Cooper
Quoted 30 lines · Jan Beulich
Quoted 23 lines · Andrew Cooper
Quoted 13 lines · Jan Beulich
Quoted 9 lines · Andrew Cooper

MISRA Rule 13.6 doesn't like having an expression in a sizeof() which potentially has side effects.

Address several violations by pulling the expression out into a local variable.

No functional change.

with one caveat:

Quoted 9 lines

xen/arch/x86/irq.c static void cf_check irq_guest_eoi_timer_fn(void *data) · line 1153

Quoted 7 lines
xen/arch/x86/irq.c +1 -0
@@ -1150,8 +1150,9 @@ static void cf_check irq_guest_eoi_timer_fn(void *data)
      {
          struct domain *d = action->guest[i];
          unsigned int pirq = domain_irq_to_pirq(d, irq);
+        struct pirq *pirq_info = pirq_info(d, pirq);

Misra won't like the var's name matching the macro's. Can we go with just "info"?

Quoted 4 lines

Ah - missed that.

I can name it to just info, but I considered "struct pirq *info" to be a little odd.

I agree, but what do you do with another "pirq" already there.

Quoted 8 lines
Quoted 5 lines

Or wait, what about

         struct pirq *pirq = pirq_info(d, domain_irq_to_pirq(d, irq));

?

That should work.  I'll switch to this locally, and wait for the feedback on whether the patch works for 13.6.

I confirm that both versions of the patch address some violations of 13.6.

Signature · 3 lines
Federico Serafini, M.Sc.

Software Engineer, BUGSENG (http://bugseng.com)
#6 lore raw
In reply to Andrew Cooper
Quoted 24 lines · Andrew Cooper
Quoted 13 lines · Jan Beulich
Quoted 9 lines · Andrew Cooper

MISRA Rule 13.6 doesn't like having an expression in a sizeof() which potentially has side effects.

Address several violations by pulling the expression out into a local variable.

No functional change.

with one caveat:

Quoted 9 lines

xen/arch/x86/irq.c static void cf_check irq_guest_eoi_timer_fn(void *data) · line 1153

Quoted 7 lines
xen/arch/x86/irq.c +1 -0
@@ -1150,8 +1150,9 @@ static void cf_check irq_guest_eoi_timer_fn(void *data)
      {
          struct domain *d = action->guest[i];
          unsigned int pirq = domain_irq_to_pirq(d, irq);
+        struct pirq *pirq_info = pirq_info(d, pirq);

Misra won't like the var's name matching the macro's. Can we go with just "info"?

Quoted 4 lines

Ah - missed that.

I can name it to just info, but I considered "struct pirq *info" to be a little odd.

The local variable is a non-callable entity;
"clashes" between function-like macros and non-callable entities will be deviated (as agreed during MISRA meetings).

Signature · 3 lines
Federico Serafini, M.Sc.

Software Engineer, BUGSENG (http://bugseng.com)