Skip to contentSkip to conversation

xen: address MISRA C:2012 Rule 5.3

PATCH In review Nicola Vetrini 4 participants 8 messages Aug 9, 2023 – Aug 10, 2023

lore
Share & tools
lore
#0 lore raw

cover xen: address MISRA C:2012 Rule 5.3

This series contains two patches left from previous series addressing the same MISRA Rule [1] [2], to make a standalone patch with the more involved changes that the first patch of [1] brings. The review comments on the respective threads about these patches have been addressed.

[1] https://lore.kernel.org/xen-devel/[email protected]/
[2] https://lore.kernel.org/xen-devel/[email protected]/

Nicola Vetrini (2):
x86/vmsi: rename variables to address MISRA C:2012 Rule 5.3 xen/delay: address MISRA C:2012 Rule 5.3.

 xen/arch/x86/hvm/vmsi.c | 22 +++++++++++-----------
 xen/include/xen/delay.h |  8 ++++++--
 2 files changed, 17 insertions(+), 13 deletions(-)

--
2.34.1

#1 lore raw

PATCH 1/2 x86/vmsi: rename variables to address MISRA C:2012 Rule 5.3

The local variables 'irq_desc' shadow the homonymous global variable, declared in 'xen/arch/x86/include/asm/irq.h', therefore they are renamed 'irqd' for consistency.

---
 xen/arch/x86/hvm/vmsi.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
xen/arch/x86/hvm/vmsi.c +11 -11
index 3cd4923060..128f236362 100644
@@ -462,7 +462,7 @@ static void del_msixtbl_entry(struct msixtbl_entry *entry)
 
 int msixtbl_pt_register(struct domain *d, struct pirq *pirq, uint64_t gtable)
 {
-    struct irq_desc *irq_desc;
+    struct irq_desc *irqd;
     struct msi_desc *msi_desc;
     struct pci_dev *pdev;
     struct msixtbl_entry *entry, *new_entry;
@@ -482,14 +482,14 @@ int msixtbl_pt_register(struct domain *d, struct pirq *pirq, uint64_t gtable)
     if ( !new_entry )
         return -ENOMEM;
 
-    irq_desc = pirq_spin_lock_irq_desc(pirq, NULL);
-    if ( !irq_desc )
+    irqd = pirq_spin_lock_irq_desc(pirq, NULL);
+    if ( !irqd )
     {
         xfree(new_entry);
         return r;
     }
 
-    msi_desc = irq_desc->msi_desc;
+    msi_desc = irqd->msi_desc;
     if ( !msi_desc )
         goto out;
 
@@ -508,7 +508,7 @@ found:
     r = 0;
 
 out:
-    spin_unlock_irq(&irq_desc->lock);
+    spin_unlock_irq(&irqd->lock);
     xfree(new_entry);
 
     if ( !r )
@@ -533,7 +533,7 @@ out:
 
 void msixtbl_pt_unregister(struct domain *d, struct pirq *pirq)
 {
-    struct irq_desc *irq_desc;
+    struct irq_desc *irqd;
     struct msi_desc *msi_desc;
     struct pci_dev *pdev;
     struct msixtbl_entry *entry;
@@ -544,11 +544,11 @@ void msixtbl_pt_unregister(struct domain *d, struct pirq *pirq)
     if ( !msixtbl_initialised(d) )
         return;
 
-    irq_desc = pirq_spin_lock_irq_desc(pirq, NULL);
-    if ( !irq_desc )
+    irqd = pirq_spin_lock_irq_desc(pirq, NULL);
+    if ( !irqd )
         return;
 
-    msi_desc = irq_desc->msi_desc;
+    msi_desc = irqd->msi_desc;
     if ( !msi_desc )
         goto out;
 
@@ -559,14 +559,14 @@ void msixtbl_pt_unregister(struct domain *d, struct pirq *pirq)
             goto found;
 
 out:
-    spin_unlock_irq(&irq_desc->lock);
+    spin_unlock_irq(&irqd->lock);
     return;
 
 found:
     if ( !atomic_dec_and_test(&entry->refcnt) )
         del_msixtbl_entry(entry);
 
-    spin_unlock_irq(&irq_desc->lock);
+    spin_unlock_irq(&irqd->lock);
 }
 
 void msixtbl_init(struct domain *d)
Signature · 1 line
2.34.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [XEN PATCH 1/2] x86/vmsi: rename variables to address MISRA C:2012 Rule 5.3

Quoted 3 lines · Nicola Vetrini

The local variables 'irq_desc' shadow the homonymous global variable, declared in 'xen/arch/x86/include/asm/irq.h', therefore they are renamed 'irqd' for consistency.

Perhaps with "for consistency" dropped (or else clarified what this is to be consistent with) ...

Quoted 1 line

Jan

#3 lore raw

Re: [XEN PATCH 1/2] x86/vmsi: rename variables to address MISRA C:2012 Rule 5.3

Quoted 5 lines · Jan Beulich
Quoted 3 lines · Nicola Vetrini

The local variables 'irq_desc' shadow the homonymous global variable, declared in 'xen/arch/x86/include/asm/irq.h', therefore they are renamed 'irqd' for consistency.

Quoted 8 lines

Perhaps with "for consistency" dropped (or else clarified what this is to be consistent with) ...

Quoted 1 line

Jan

Good point.

Signature · 2 lines
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)
#4 lore raw

PATCH 2/2 xen/delay: address MISRA C:2012 Rule 5.3.

In reply to Nicola Vetrini

The variable 'msec' declared in the macro shadows the local variable in 'ehci_dbgp_bios_handoff', but to prevent any future clashes with other functions the macro is converted to a static inline function.

No functional change.

---
 xen/include/xen/delay.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
xen/include/xen/delay.h +6 -2
index 9d70ef035f..9150226271 100644
@@ -4,7 +4,11 @@
 /* Copyright (C) 1993 Linus Torvalds */
 
 #include <asm/delay.h>
-#define mdelay(n) (\
-	{unsigned long msec=(n); while (msec--) udelay(1000);})
+
+static inline void mdelay(unsigned long msec)
+{
+    while ( msec-- )
+        udelay(1000);
+}
 
 #endif /* defined(_LINUX_DELAY_H) */
Signature · 1 line
2.34.1
Reviewed-by on v1 2/2
#5 lore raw

Re: [XEN PATCH 2/2] xen/delay: address MISRA C:2012 Rule 5.3.

Hi Nicola,

Quoted 8 lines · Nicola Vetrini

The variable 'msec' declared in the macro shadows the local variable in 'ehci_dbgp_bios_handoff', but to prevent any future clashes with other functions the macro is converted to a static inline function.

No functional change.

Cheers,

Signature · 1 line
Julien Grall
#6 lore raw

Re: [XEN PATCH 2/2] xen/delay: address MISRA C:2012 Rule 5.3.

In reply to Nicola Vetrini
Quoted 21 lines · Nicola Vetrini

The variable 'msec' declared in the macro shadows the local variable in 'ehci_dbgp_bios_handoff', but to prevent any future clashes with other functions the macro is converted to a static inline function.

No functional change.

---
xen/include/xen/delay.h | 8 ++++++--

1 file changed, 6 insertions(+), 2 deletions(-)
xen/include/xen/delay.h +0 -0
index 9d70ef035f..9150226271 100644

xen/include/xen/delay.h line 10

Quoted 9 lines
xen/include/xen/delay.h +4 -2
@@ -4,7 +4,11 @@
 /* Copyright (C) 1993 Linus Torvalds */
 
 #include <asm/delay.h>
-#define mdelay(n) (\
- {unsigned long msec=(n); while (msec--) udelay(1000);})
+
+static inline void mdelay(unsigned long msec)
+{
+    while ( msec-- )

Does misra allows to modify the function parameters? (Truly asking because IDK)

Quoted 8 lines
xen/include/xen/delay.h +2 -0
+        udelay(1000);
+}
 
 #endif /* defined(_LINUX_DELAY_H) */
Signature · 1 line
2.34.1
#7 lore raw

Re: [XEN PATCH 2/2] xen/delay: address MISRA C:2012 Rule 5.3.

Quoted 21 lines · Luca Fancellu
Quoted 21 lines · Nicola Vetrini

The variable 'msec' declared in the macro shadows the local variable in 'ehci_dbgp_bios_handoff', but to prevent any future clashes with other functions the macro is converted to a static inline function.

No functional change.

---
xen/include/xen/delay.h | 8 ++++++--

1 file changed, 6 insertions(+), 2 deletions(-)
xen/include/xen/delay.h +0 -0
index 9d70ef035f..9150226271 100644
@@ -4,7 +4,11 @@
 /* Copyright (C) 1993 Linus Torvalds */
 
Quoted 10 lines

xen/include/xen/delay.h line 10

Quoted 7 lines
xen/include/xen/delay.h +4 -2
 #include <asm/delay.h>
-#define mdelay(n) (\
- {unsigned long msec=(n); while (msec--) udelay(1000);})
+
+static inline void mdelay(unsigned long msec)
+{
+    while ( msec-- )

Does misra allows to modify the function parameters? (Truly asking because IDK)

I checked: there's an advisory (R17.8) that disallows this, but since advisories (apart from a couple of selected ones) are not taken into consideration for compliance, so it's not a big deal. Even less so since it's not a pointer type.

Signature · 2 lines
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)