Skip to contentSkip to conversation

Fix MISRA C 2012 violations

PATCH Superseded Xenia Ragiadakou 4 participants 16 messages Jun 26, 2022 – Jun 29, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Fix MISRA C 2012 violations

Resolve MISRA C 2012 Rule 8.4 warnings.

Xenia Ragiadakou (5):
xen/common: page_alloc: Fix MISRA C 2012 Rule 8.7 violation xen/common: vm_event: Fix MISRA C 2012 Rule 8.7 violation xen/drivers: iommu: Fix MISRA C 2012 Rule 8.7 violation xen/sched: credit: Fix MISRA C 2012 Rule 8.7 violation xen/arm64: traps: Fix MISRA C 2012 Rule 8.4 violations

 xen/arch/arm/arm64/traps.c             | 1 +
 xen/arch/arm/include/asm/arm64/traps.h | 2 ++
 xen/common/page_alloc.c                | 4 ++--
 xen/common/sched/credit.c              | 2 +-
 xen/common/vm_event.c                  | 2 +-
 xen/drivers/passthrough/iommu.c        | 2 +-
 6 files changed, 8 insertions(+), 5 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/5 xen/common: page_alloc: Fix MISRA C 2012 Rule 8.7 violation

The variables page_offlined_list and page_broken_list are referenced only in page_alloc.c.
Change their linkage from external to internal by adding the storage-class specifier static to their definitions.

This patch aims to resolve indirectly a MISRA C 2012 Rule 8.4 violation warning.

---
 xen/common/page_alloc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/common/page_alloc.c +2 -2
index 000ae6b972..fe0e15429a 100644
@@ -235,9 +235,9 @@ static unsigned int dma_bitsize;
 integer_param("dma_bits", dma_bitsize);
 
 /* Offlined page list, protected by heap_lock. */
-PAGE_LIST_HEAD(page_offlined_list);
+static PAGE_LIST_HEAD(page_offlined_list);
 /* Broken page list, protected by heap_lock. */
-PAGE_LIST_HEAD(page_broken_list);
+static PAGE_LIST_HEAD(page_broken_list);
 
 /*************************
  * BOOT-TIME ALLOCATOR
Signature · 1 line
2.34.1
Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] xen/common: page_alloc: Fix MISRA C 2012 Rule 8.7 violation

Quoted 8 lines · Xenia Ragiadakou

The variables page_offlined_list and page_broken_list are referenced only in page_alloc.c.
Change their linkage from external to internal by adding the storage-class specifier static to their definitions.

This patch aims to resolve indirectly a MISRA C 2012 Rule 8.4 violation warning.

#3 lore raw

PATCH 2/5 xen/common: vm_event: Fix MISRA C 2012 Rule 8.7 violation

In reply to Xenia Ragiadakou

The function vm_event_wake() is referenced only in vm_event.c. Change the linkage of the function from external to internal by adding the storage-class specifier static to the function definition.

This patch aims to resolve indirectly a MISRA C 2012 Rule 8.4 violation warning.

---
 xen/common/vm_event.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/vm_event.c +1 -1
index 0b99a6ea72..ecf49c38a9 100644
@@ -173,7 +173,7 @@ static void vm_event_wake_queued(struct domain *d, struct vm_event_domain *ved)
  * call vm_event_wake() again, ensuring that any blocked vCPUs will get
  * unpaused once all the queued vCPUs have made it through.
  */
-void vm_event_wake(struct domain *d, struct vm_event_domain *ved)
+static void vm_event_wake(struct domain *d, struct vm_event_domain *ved)
 {
     if ( !list_empty(&ved->wq.list) )
         vm_event_wake_queued(d, ved);
Signature · 1 line
2.34.1
Reviewed-by on v1 2/5
#4 lore raw

Re: [PATCH 2/5] xen/common: vm_event: Fix MISRA C 2012 Rule 8.7 violation

Quoted 5 lines · Xenia Ragiadakou

The function vm_event_wake() is referenced only in vm_event.c. Change the linkage of the function from external to internal by adding the storage-class specifier static to the function definition.

This patch aims to resolve indirectly a MISRA C 2012 Rule 8.4 violation warning.

Actually also for patch 1 - this is slightly confusing, as the title talks about 8.7. At first I suspected a typo. May I suggest to add "also" (which I think could be easily done while committing)?

Quoted 1 line
author
#5 lore raw

Re: [PATCH 2/5] xen/common: vm_event: Fix MISRA C 2012 Rule 8.7 violation

Hi Jan,

Quoted 9 lines · Jan Beulich
Quoted 5 lines · Xenia Ragiadakou

The function vm_event_wake() is referenced only in vm_event.c. Change the linkage of the function from external to internal by adding the storage-class specifier static to the function definition.

This patch aims to resolve indirectly a MISRA C 2012 Rule 8.4 violation warning.

Actually also for patch 1 - this is slightly confusing, as the title talks about 8.7. At first I suspected a typo. May I suggest to add "also" (which I think could be easily done while committing)?

This is actually a violation of MISRA C 2012 Rule 8.7 (Advisory), which states that functions referenced in only one translation unit should not be defined with external linkage. This violation triggers a MISRA C 2012 Rule 8.4 violation warning, because the function is defined with external linkage without a visible declaration at the point of definition. I thought that this does not make it a violation of MISRA C 2012 Rule 8.4.

Quoted 3 lines
Quoted 1 line
#6 lore raw

Re: [PATCH 2/5] xen/common: vm_event: Fix MISRA C 2012 Rule 8.7 violation

Quoted 12 lines · xenia
Quoted 9 lines · Jan Beulich
Quoted 5 lines · Xenia Ragiadakou

The function vm_event_wake() is referenced only in vm_event.c. Change the linkage of the function from external to internal by adding the storage-class specifier static to the function definition.

This patch aims to resolve indirectly a MISRA C 2012 Rule 8.4 violation warning.

Actually also for patch 1 - this is slightly confusing, as the title talks about 8.7. At first I suspected a typo. May I suggest to add "also" (which I think could be easily done while committing)?

Quoted 7 lines

This is actually a violation of MISRA C 2012 Rule 8.7 (Advisory), which states that functions referenced in only one translation unit should not be defined with external linkage.
This violation triggers a MISRA C 2012 Rule 8.4 violation warning, because the function is defined with external linkage without a visible declaration at the point of definition.
I thought that this does not make it a violation of MISRA C 2012 Rule 8.4.

I think this is a violation of both rules. It would be a violation of only 8.7 if the function had a declaration, but still wasn't used outside its defining CU.

Jan

author
#7 lore raw

Re: [PATCH 2/5] xen/common: vm_event: Fix MISRA C 2012 Rule 8.7 violation

Hi Jan,

Quoted 19 lines · Jan Beulich
Quoted 11 lines · xenia
Quoted 9 lines · Jan Beulich
Quoted 5 lines · Xenia Ragiadakou

The function vm_event_wake() is referenced only in vm_event.c. Change the linkage of the function from external to internal by adding the storage-class specifier static to the function definition.

This patch aims to resolve indirectly a MISRA C 2012 Rule 8.4 violation warning.

Actually also for patch 1 - this is slightly confusing, as the title talks about 8.7. At first I suspected a typo. May I suggest to add "also" (which I think could be easily done while committing)?

Quoted 7 lines

This is actually a violation of MISRA C 2012 Rule 8.7 (Advisory), which states that functions referenced in only one translation unit should not be defined with external linkage.
This violation triggers a MISRA C 2012 Rule 8.4 violation warning, because the function is defined with external linkage without a visible declaration at the point of definition.
I thought that this does not make it a violation of MISRA C 2012 Rule 8.4.

Quoted 3 lines

I think this is a violation of both rules. It would be a violation of only 8.7 if the function had a declaration, but still wasn't used outside its defining CU.

So you are suggesting to change the line
"This patch aims to resolve indirectly a MISRA C 2012 Rule 8.4 violation warning." to
"Also, this patch aims to resolve indirectly a MISRA C 2012 Rule 8.4 violation warning."

I will wait one more day in case there is some input for the last patch, and I will send a v2 with the above changed.

Xenia

Reviewed-by on v1 2/5
#8 lore raw

Re: [PATCH 2/5] xen/common: vm_event: Fix MISRA C 2012 Rule 8.7 violation

In reply to Xenia Ragiadakou
Quoted 7 lines · Xenia Ragiadakou

The function vm_event_wake() is referenced only in vm_event.c. Change the linkage of the function from external to internal by adding the storage-class specifier static to the function definition.

This patch aims to resolve indirectly a MISRA C 2012 Rule 8.4 violation warning.

Quoted 21 lines
---
 xen/common/vm_event.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/vm_event.c +1 -1
index 0b99a6ea72..ecf49c38a9 100644
@@ -173,7 +173,7 @@ static void vm_event_wake_queued(struct domain *d, struct vm_event_domain *ved)
  * call vm_event_wake() again, ensuring that any blocked vCPUs will get
  * unpaused once all the queued vCPUs have made it through.
  */
-void vm_event_wake(struct domain *d, struct vm_event_domain *ved)
+static void vm_event_wake(struct domain *d, struct vm_event_domain *ved)
 {
     if ( !list_empty(&ved->wq.list) )
         vm_event_wake_queued(d, ved);
Signature · 1 line
2.34.1
#9 lore raw

PATCH 3/5 xen/drivers: iommu: Fix MISRA C 2012 Rule 8.7 violation

In reply to Xenia Ragiadakou

The variable iommu_crash_disable is referenced only in one translation unit. Change its linkage from external to internal by adding the storage-class specifier static to its definition.

This patch aims to resolve indirectly a MISRA C 2012 Rule 8.4 violation warning.

---
 xen/drivers/passthrough/iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/drivers/passthrough/iommu.c +1 -1
index 75df3aa8dd..77f64e6174 100644
@@ -29,7 +29,7 @@ bool_t __initdata iommu_enable = 1;
 bool_t __read_mostly iommu_enabled;
 bool_t __read_mostly force_iommu;
 bool_t __read_mostly iommu_verbose;
-bool_t __read_mostly iommu_crash_disable;
+static bool_t __read_mostly iommu_crash_disable;
 
 #define IOMMU_quarantine_none         0 /* aka false */
 #define IOMMU_quarantine_basic        1 /* aka true */
Signature · 1 line
2.34.1
Reviewed-by on v1 3/5
#10 lore raw

Re: [PATCH 3/5] xen/drivers: iommu: Fix MISRA C 2012 Rule 8.7 violation

Quoted 7 lines · Xenia Ragiadakou

The variable iommu_crash_disable is referenced only in one translation unit. Change its linkage from external to internal by adding the storage-class specifier static to its definition.

This patch aims to resolve indirectly a MISRA C 2012 Rule 8.4 violation warning.

(with the same remark as on patch 2)

#11 lore raw

PATCH 4/5 xen/sched: credit: Fix MISRA C 2012 Rule 8.7 violation

In reply to Xenia Ragiadakou

The per-cpu variable last_tickle_cpu is referenced only in credit.c. Change its linkage from external to internal by adding the storage-class specifier static to its definitions.

This patch aims to resolve indirectly a MISRA C 2012 Rule 8.4 violation warning.

---
 xen/common/sched/credit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/sched/credit.c +1 -1
index 4d3bd8cba6..47945c2834 100644
@@ -348,7 +348,7 @@ static void burn_credits(struct csched_unit *svc, s_time_t now)
 static bool __read_mostly opt_tickle_one_idle = true;
 boolean_param("tickle_one_idle_cpu", opt_tickle_one_idle);
 
-DEFINE_PER_CPU(unsigned int, last_tickle_cpu);
+static DEFINE_PER_CPU(unsigned int, last_tickle_cpu);
 
 static inline void __runq_tickle(const struct csched_unit *new)
 {
Signature · 1 line
2.34.1
Reviewed-by on v1 4/5
#12 lore raw

Re: [PATCH 4/5] xen/sched: credit: Fix MISRA C 2012 Rule 8.7 violation

Quoted 7 lines · Xenia Ragiadakou

The per-cpu variable last_tickle_cpu is referenced only in credit.c. Change its linkage from external to internal by adding the storage-class specifier static to its definitions.

This patch aims to resolve indirectly a MISRA C 2012 Rule 8.4 violation warning.

(again with the same remark as on patch 2)

Reviewed-by on v1 4/5
#13 lore raw

Re: [PATCH 4/5] xen/sched: credit: Fix MISRA C 2012 Rule 8.7 violation

In reply to Xenia Ragiadakou
Quoted 7 lines · Xenia Ragiadakou

The per-cpu variable last_tickle_cpu is referenced only in credit.c. Change its linkage from external to internal by adding the storage-class specifier static to its definitions.

This patch aims to resolve indirectly a MISRA C 2012 Rule 8.4 violation warning.

Quoted 21 lines
---
 xen/common/sched/credit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/sched/credit.c +1 -1
index 4d3bd8cba6..47945c2834 100644
@@ -348,7 +348,7 @@ static void burn_credits(struct csched_unit *svc, s_time_t now)
 static bool __read_mostly opt_tickle_one_idle = true;
 boolean_param("tickle_one_idle_cpu", opt_tickle_one_idle);
 
-DEFINE_PER_CPU(unsigned int, last_tickle_cpu);
+static DEFINE_PER_CPU(unsigned int, last_tickle_cpu);
 
 static inline void __runq_tickle(const struct csched_unit *new)
 {
Signature · 1 line
2.34.1
#14 lore raw

PATCH 5/5 xen/arm64: traps: Fix MISRA C 2012 Rule 8.4 violations

In reply to Xenia Ragiadakou

Add a function prototype for do_bad_mode() in <asm/arm64/traps.h> and include header <asm/traps.h> in traps.c, so that the declarations of the functions do_bad_mode() and finalize_instr_emulation(), which have external linkage, are visible before the function definitions.

---
 xen/arch/arm/arm64/traps.c             | 1 +
 xen/arch/arm/include/asm/arm64/traps.h | 2 ++
 2 files changed, 3 insertions(+)
xen/arch/arm/arm64/traps.c +1 -0
index 3f8858acec..a995ad7c2c 100644
@@ -22,6 +22,7 @@
 #include <asm/hsr.h>
 #include <asm/system.h>
 #include <asm/processor.h>
+#include <asm/traps.h>
 
 #include <public/xen.h>
 
xen/arch/arm/include/asm/arm64/traps.h +2 -0
index 2379b578cb..a347cb13d6 100644
@@ -6,6 +6,8 @@ void inject_undef64_exception(struct cpu_user_regs *regs, int instr_len);
 void do_sysreg(struct cpu_user_regs *regs,
                const union hsr hsr);
 
+void do_bad_mode(struct cpu_user_regs *regs, int reason);
+
 #endif /* __ASM_ARM64_TRAPS__ */
 /*
  * Local variables:
Signature · 1 line
2.34.1
Reviewed-by on v1 5/5
#15 lore raw

Re: [PATCH 5/5] xen/arm64: traps: Fix MISRA C 2012 Rule 8.4 violations

Hi Xenia,

Quoted 8 lines · Xenia Ragiadakou

Add a function prototype for do_bad_mode() in <asm/arm64/traps.h> and include header <asm/traps.h> in traps.c, so that the declarations of the functions do_bad_mode() and finalize_instr_emulation(), which have external linkage, are visible before the function definitions.

Cheers
Bertrand

Quoted 33 lines

---
xen/arch/arm/arm64/traps.c | 1 +
xen/arch/arm/include/asm/arm64/traps.h | 2 ++

2 files changed, 3 insertions(+)
xen/arch/arm/arm64/traps.c +1 -0
index 3f8858acec..a995ad7c2c 100644
@@ -22,6 +22,7 @@
 #include <asm/hsr.h>
 #include <asm/system.h>
 #include <asm/processor.h>
+#include <asm/traps.h>
 
 #include <public/xen.h>
 
xen/arch/arm/include/asm/arm64/traps.h +2 -0
index 2379b578cb..a347cb13d6 100644
@@ -6,6 +6,8 @@ void inject_undef64_exception(struct cpu_user_regs *regs, int instr_len);
 void do_sysreg(struct cpu_user_regs *regs,
               const union hsr hsr);
 
+void do_bad_mode(struct cpu_user_regs *regs, int reason);
+
 #endif /* __ASM_ARM64_TRAPS__ */
 /*
 * Local variables:
Signature · 1 line
2.34.1