Skip to contentSkip to conversation

fix violations of MISRA C:2012 Rule 3.1

PATCH In review Nicola Vetrini 6 participants 19 messages Jun 29, 2023 – Jul 6, 2023

lore
Share & tools
lore
#0 lore raw

v3 cover fix violations of MISRA C:2012 Rule 3.1

Hi all,

This patch series is about the violations present in the Xen sources of Rule 3.1 from MISRA C:2012, whose headline states:
"The character sequences '/*' and '//' shall not be used within a comment".

In the context of the effort to bring xen into compliance w.r.t. MISRA C:2012, and Rule 3.1 being already approved for the project (as evidenced by `docs/misra/rules.rst'), these violations need to be fixed.

Most of the violations are due to the presence of links to webpages within C-style comment blocks, such as:

xen/arch/arm/include/asm/smccc.h:37.1-41.3
/*
* This file provides common defines for ARM SMC Calling Convention as
* specified in
* http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html
*/

In this case, I propose to deviate all of these occurrences with a project deviation to be captured by a tool configuration (not included in any patch from this series).

There are, however, a few other violations that do not fall under this category, which are the focus of the following set of patches. They either:

1. remove the nested '//' character sequence within a block comment;
2. replacing the nested '//' character sequence with ARM asm comments or similar constructs that do not violate the rule.

Thanks,
Nicola

Nicola Vetrini (3):
xen/arch/arm: fix violations of MISRA C:2012 Rule 3.1 xen/drivers/passthrough/arm/smmu-v3.c: fix violations of MISRA C:2012

    Rule 3.1

xen: fix violations of MISRA C:2012 Rule 3.1

 xen/arch/arm/include/asm/arm32/flushtlb.h | 8 ++++----
 xen/arch/arm/include/asm/arm64/flushtlb.h | 8 ++++----
 xen/common/xmalloc_tlsf.c                 | 4 +---
 xen/drivers/passthrough/arm/smmu-v3.c     | 8 ++++----
 xen/include/xen/atomic.h                  | 2 +-
 5 files changed, 14 insertions(+), 16 deletions(-)

--
2.34.1

#1 lore raw

PATCH v3 1/3 xen/arch/arm: fix violations of MISRA C:2012 Rule 3.1

In the files `xen/arch/arm/include/asm/arm(32|64)/flushtlb.h' there are a few occurrences of nested '//' character sequences inside C-style comment blocks, which violate Rule 3.1. The patch aims to resolve those by changing the inner comments to arm asm comments, delimited by ';' instead.

---
Changes:
- Resending the patch with the right maintainers in CC. Changes in V2:
- Split the patch into a series and reworked the fix.
- Apply the fix to the arm32 `flushtlb.h' file, for consistency Changes in V3:
- Switched to arm asm comment in `arm(32|64)/flushtlb.h'

---
 xen/arch/arm/include/asm/arm32/flushtlb.h | 8 ++++----
 xen/arch/arm/include/asm/arm64/flushtlb.h | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)
xen/arch/arm/include/asm/arm32/flushtlb.h +4 -4
index 22ee3b317b..61c25a3189 100644
@@ -4,10 +4,10 @@
 /*
  * Every invalidation operation use the following patterns:
  *
- * DSB ISHST        // Ensure prior page-tables updates have completed
- * TLBI...          // Invalidate the TLB
- * DSB ISH          // Ensure the TLB invalidation has completed
- * ISB              // See explanation below
+ * DSB ISHST        ; Ensure prior page-tables updates have completed
+ * TLBI...          ; Invalidate the TLB
+ * DSB ISH          ; Ensure the TLB invalidation has completed
+ * ISB              ; See explanation below
  *
  * For Xen page-tables the ISB will discard any instructions fetched
  * from the old mappings.
xen/arch/arm/include/asm/arm64/flushtlb.h +4 -4
index 56c6fc763b..45642201d1 100644
@@ -4,10 +4,10 @@
 /*
  * Every invalidation operation use the following patterns:
  *
- * DSB ISHST        // Ensure prior page-tables updates have completed
- * TLBI...          // Invalidate the TLB
- * DSB ISH          // Ensure the TLB invalidation has completed
- * ISB              // See explanation below
+ * DSB ISHST        ; Ensure prior page-tables updates have completed
+ * TLBI...          ; Invalidate the TLB
+ * DSB ISH          ; Ensure the TLB invalidation has completed
+ * ISB              ; See explanation below
  *
  * ARM64_WORKAROUND_REPEAT_TLBI:
  * Modification of the translation table for a virtual address might lead to
Signature · 1 line
2.34.1
#6 lore raw

PATCH v3 2/3 xen/drivers/passthrough/arm/smmu-v3.c: fix violations of MISRA C:2012 Rule 3.1

In reply to Nicola Vetrini

In the file `xen/drivers/passthrough/arm/smmu-v3.c' there are a few occurrences of nested '//' character sequences inside C-style comment blocks, which violate Rule 3.1.

The patch aims to resolve those by replacing the nested comments with equivalent constructs that do not violate the rule.

Changes:
- Resending the patch with the right maintainers in CC. Changes in V2:
- Split the patch into a series and reworked the fix.
- Apply the fix to the arm32 `flushtlb.h' file, for consistency Changes in V3:
- Revised the comment to make it clear the function the parallel control flows in the comment belong to.

---
 xen/drivers/passthrough/arm/smmu-v3.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
xen/drivers/passthrough/arm/smmu-v3.c +4 -4
index 720aa69ff2..cdbb505134 100644
@@ -1047,10 +1047,10 @@ static int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain,
 	 * before we read 'nr_ats_masters' in case of a concurrent call to
 	 * arm_smmu_enable_ats():
 	 *
-	 *	// unmap()			// arm_smmu_enable_ats()
-	 *	TLBI+SYNC			atomic_inc(&nr_ats_masters);
-	 *	smp_mb();			[...]
-	 *	atomic_read(&nr_ats_masters);	pci_enable_ats() // writel()
+	 *	--- unmap() ---                 --- arm_smmu_enable_ats() ---
+	 *	TLBI+SYNC                       atomic_inc(&nr_ats_masters);
+	 *	smp_mb();                       [...]
+	 *	atomic_read(&nr_ats_masters);   pci_enable_ats() (see writel())
 	 *
 	 * Ensures that we always see the incremented 'nr_ats_masters' count if
 	 * ATS was enabled at the PCI device before completion of the TLBI.
Signature · 1 line
2.34.1
#12 lore raw

PATCH v3 3/3 xen: fix violations of MISRA C:2012 Rule 3.1

In reply to Nicola Vetrini

In the files modified by this patch there are a few occurrences of nested '//' character sequences inside C-style comment blocks, which violate Rule 3.1. The patch aims to resolve those by removing the nested comments.

In the file 'xen/common/xmalloc_tlsf.c' the comment has been replaces by an ASSERT, to ensure that the invariant in the comment is enforced.

In the file 'xen/include/xen/atomic.h' the nested comment has been removed, since the code sample is already explained by the preceding comment.

Changes:
- Resending the patch with the right maintainers in CC. Changes in V2:
- Split the patch into a series and reworked the fix;
- Apply the fix to the arm32 `flushtlb.h' file, for consistency. Changes in V3:
- Replaced commmented-out 'if' with an ASSERT( *fl >= 0 ).

---
 xen/common/xmalloc_tlsf.c | 4 +---
 xen/include/xen/atomic.h  | 2 +-
 2 files changed, 2 insertions(+), 4 deletions(-)
xen/common/xmalloc_tlsf.c +1 -3
index 75bdf18c4e..95affcc571 100644
@@ -140,9 +140,7 @@ static inline void MAPPING_SEARCH(unsigned long *r, int *fl, int *sl)
         *fl = flsl(*r) - 1;
         *sl = (*r >> (*fl - MAX_LOG2_SLI)) - MAX_SLI;
         *fl -= FLI_OFFSET;
-        /*if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
-         *fl = *sl = 0;
-         */
+        ASSERT( *fl >= 0 );
         *r &= ~t;
     }
 }
xen/include/xen/atomic.h +1 -1
index 529213ebbb..fa750a18ae 100644
@@ -78,7 +78,7 @@ static inline void _atomic_set(atomic_t *v, int i);
  *      int old = atomic_read(&v);
  *      int new = old + 1;
  *      if ( likely(old == atomic_cmpxchg(&v, old, new)) )
- *          break; // success!
+ *          break;
  *  }
  */
 static inline int atomic_cmpxchg(atomic_t *v, int old, int new);
Signature · 1 line
2.34.1
Reviewed-by on v3 1/3
#2 lore raw

Re: [XEN PATCH v3 1/3] xen/arch/arm: fix violations of MISRA C:2012 Rule 3.1

In reply to Nicola Vetrini
Quoted 10 lines · Nicola Vetrini

In the files `xen/arch/arm/include/asm/arm(32|64)/flushtlb.h' there are a few occurrences of nested '//' character sequences inside C-style comment blocks, which violate Rule 3.1. The patch aims to resolve those by changing the inner comments to arm asm comments, delimited by ';' instead.

Can I suggest another commit title:
“xen/arm: tlbflush: fix violations of MISRA C:2012 Rule 3.1"

Sometimes when I am not sure on how to deal with prefixes, I check to the git history of the line I am changing, for these lines there was a commit from Julien using these prefixes. I’m using vs code with GitLens extension, that ease a lot this kind of checks.

Apart from that, the changes looks good to me:

#3 lore raw

Re: [XEN PATCH v3 1/3] xen/arch/arm: fix violations of MISRA C:2012 Rule 3.1

Quoted 14 lines · Luca Fancellu
Quoted 10 lines · Nicola Vetrini

In the files `xen/arch/arm/include/asm/arm(32|64)/flushtlb.h' there are a few occurrences of nested '//' character sequences inside C-style comment blocks, which violate Rule 3.1. The patch aims to resolve those by changing the inner comments to arm asm comments, delimited by ';' instead.

Can I suggest another commit title:
“xen/arm: tlbflush: fix violations of MISRA C:2012 Rule 3.1"

Quoted 9 lines

Sometimes when I am not sure on how to deal with prefixes, I check to the git history of the line I am changing, for these lines there was a commit from Julien using these prefixes. I’m using vs code with GitLens extension, that ease a lot this kind of checks.

Apart from that, the changes looks good to me:

Thanks for the suggestion, I'll use it from now on

Signature · 2 lines
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)
Reviewed-by on v3 2/3
#7 lore raw

Re: [XEN PATCH v3 2/3] xen/drivers/passthrough/arm/smmu-v3.c: fix violations of MISRA C:2012 Rule 3.1

In reply to Nicola Vetrini
Quoted 5 lines · Nicola Vetrini

In the file `xen/drivers/passthrough/arm/smmu-v3.c' there are a few occurrences

here you use a different character to enclose the file path (` vs ‘) may I suggest to use only (‘)?

Quoted 7 lines

of nested '//' character sequences inside C-style comment blocks, which violate Rule 3.1.

The patch aims to resolve those by replacing the nested comments with equivalent constructs that do not violate the rule.

You are missing the “---“ here, meaning that the lines below are part of the commit message and I’m sure you don’t want that.

Also here, may I suggest to use this commit title instead? “xen/arm: smmuv3: Fix violations of MISRA C:2012 Rule 3.1”

Apart from that, changes looks good to me:

Will be the maintainer/committer to decide if addressing these comment, if accepted, on commit or if you need to send another version, in which case you can retain my r-by provided that no other modifications are done.

Quoted 35 lines

Changes:
- Resending the patch with the right maintainers in CC. Changes in V2:
- Split the patch into a series and reworked the fix.
- Apply the fix to the arm32 `flushtlb.h' file, for consistency Changes in V3:
- Revised the comment to make it clear the function the parallel control flows in the comment belong to.
---
xen/drivers/passthrough/arm/smmu-v3.c | 8 ++++----

1 file changed, 4 insertions(+), 4 deletions(-)
xen/drivers/passthrough/arm/smmu-v3.c +4 -4
index 720aa69ff2..cdbb505134 100644
@@ -1047,10 +1047,10 @@ static int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain,
 * before we read 'nr_ats_masters' in case of a concurrent call to
 * arm_smmu_enable_ats():
 *
- * // unmap() // arm_smmu_enable_ats()
- * TLBI+SYNC atomic_inc(&nr_ats_masters);
- * smp_mb(); [...]
- * atomic_read(&nr_ats_masters); pci_enable_ats() // writel()
+ * --- unmap() ---                 --- arm_smmu_enable_ats() ---
+ * TLBI+SYNC                       atomic_inc(&nr_ats_masters);
+ * smp_mb();                       [...]
+ * atomic_read(&nr_ats_masters);   pci_enable_ats() (see writel())
 *
 * Ensures that we always see the incremented 'nr_ats_masters' count if
 * ATS was enabled at the PCI device before completion of the TLBI.
Signature · 1 line
2.34.1
Reviewed-by on v3 3/3
#13 lore raw

Re: [XEN PATCH v3 3/3] xen: fix violations of MISRA C:2012 Rule 3.1

In reply to Nicola Vetrini
Quoted 9 lines · Nicola Vetrini

In the files modified by this patch there are a few occurrences of nested '//' character sequences inside C-style comment blocks, which violate Rule 3.1. The patch aims to resolve those by removing the nested comments.

In the file 'xen/common/xmalloc_tlsf.c' the comment has been replaces by

Typo: s/replaces/replaced/

Quoted 6 lines

an ASSERT, to ensure that the invariant in the comment is enforced.

In the file 'xen/include/xen/atomic.h' the nested comment has been removed, since the code sample is already explained by the preceding comment.

Same as patch 2, missing “---"

Quoted 17 lines

Changes:
- Resending the patch with the right maintainers in CC. Changes in V2:
- Split the patch into a series and reworked the fix;
- Apply the fix to the arm32 `flushtlb.h' file, for consistency. Changes in V3:
- Replaced commmented-out 'if' with an ASSERT( *fl >= 0 ).
---
xen/common/xmalloc_tlsf.c | 4 +--- xen/include/xen/atomic.h | 2 +-

2 files changed, 2 insertions(+), 4 deletions(-)
xen/common/xmalloc_tlsf.c +0 -0
index 75bdf18c4e..95affcc571 100644

xen/common/xmalloc_tlsf.c static inline void MAPPING_SEARCH(unsigned long *r, int *fl, int *sl) · line 143

Quoted 7 lines
xen/common/xmalloc_tlsf.c +1 -3
@@ -140,9 +140,7 @@ static inline void MAPPING_SEARCH(unsigned long *r, int *fl, int *sl)
        *fl = flsl(*r) - 1;
        *sl = (*r >> (*fl - MAX_LOG2_SLI)) - MAX_SLI;
        *fl -= FLI_OFFSET;
-        /*if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
-         *fl = *sl = 0;
-         */
+        ASSERT( *fl >= 0 );

I’ve checked the codebase for usage of ASSERT, but I’ve not seen use of it with spaces before and after the condition (like our if conditions) so I think they can be dropped.

Quoted 20 lines
xen/common/xmalloc_tlsf.c +0 -0
        *r &= ~t;
    }
 }
xen/include/xen/atomic.h +1 -1
index 529213ebbb..fa750a18ae 100644
@@ -78,7 +78,7 @@ static inline void _atomic_set(atomic_t *v, int i);
 *      int old = atomic_read(&v);
 *      int new = old + 1;
 *      if ( likely(old == atomic_cmpxchg(&v, old, new)) )
- *          break; // success!
+ *          break;
 *  }
 */
 static inline int atomic_cmpxchg(atomic_t *v, int old, int new);
Signature · 1 line
2.34.1

With the comments addressed:

Reviewed-by
#4 lore raw

Re: [XEN PATCH v3 1/3] xen/arch/arm: fix violations of MISRA C:2012 Rule 3.1

In reply to Luca Fancellu
Quoted 12 lines · Luca Fancellu
Quoted 8 lines · Nicola Vetrini

In the files `xen/arch/arm/include/asm/arm(32|64)/flushtlb.h' there are a few occurrences of nested '//' character sequences inside C-style comment blocks, which violate Rule 3.1. The patch aims to resolve those by changing the inner comments to arm asm comments, delimited by ';' instead.

Can I suggest another commit title:
“xen/arm: tlbflush: fix violations of MISRA C:2012 Rule 3.1"

Quoted 8 lines

Sometimes when I am not sure on how to deal with prefixes, I check to the git history of the line I am changing, for these lines there was a commit from Julien using these prefixes. I’m using vs code with GitLens extension, that ease a lot this kind of checks.

Apart from that, the changes looks good to me:

With Luca's suggestion (can be done on commit):

Reviewed-by
#8 lore raw

Re: [XEN PATCH v3 2/3] xen/drivers/passthrough/arm/smmu-v3.c: fix violations of MISRA C:2012 Rule 3.1

In reply to Luca Fancellu
Quoted 21 lines · Luca Fancellu
Quoted 3 lines · Nicola Vetrini

In the file `xen/drivers/passthrough/arm/smmu-v3.c' there are a few occurrences

here you use a different character to enclose the file path (` vs ‘) may I suggest to use only (‘)?

Quoted 7 lines

of nested '//' character sequences inside C-style comment blocks, which violate Rule 3.1.

The patch aims to resolve those by replacing the nested comments with equivalent constructs that do not violate the rule.

You are missing the “---“ here, meaning that the lines below are part of the commit message and I’m sure you don’t want that.

Also here, may I suggest to use this commit title instead? “xen/arm: smmuv3: Fix violations of MISRA C:2012 Rule 3.1”

Quoted 7 lines

Apart from that, changes looks good to me:

Will be the maintainer/committer to decide if addressing these comment, if accepted, on commit or if you need to send another version, in which case you can retain my r-by provided that no other modifications are done.

I think it can be done on commit. With the changes suggested by Luca:

Quoted 37 lines
Quoted 35 lines

Changes:
- Resending the patch with the right maintainers in CC. Changes in V2:
- Split the patch into a series and reworked the fix.
- Apply the fix to the arm32 `flushtlb.h' file, for consistency Changes in V3:
- Revised the comment to make it clear the function the parallel control flows in the comment belong to.
---
xen/drivers/passthrough/arm/smmu-v3.c | 8 ++++----

1 file changed, 4 insertions(+), 4 deletions(-)
xen/drivers/passthrough/arm/smmu-v3.c +4 -4
index 720aa69ff2..cdbb505134 100644
@@ -1047,10 +1047,10 @@ static int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain,
 * before we read 'nr_ats_masters' in case of a concurrent call to
 * arm_smmu_enable_ats():
 *
- * // unmap() // arm_smmu_enable_ats()
- * TLBI+SYNC atomic_inc(&nr_ats_masters);
- * smp_mb(); [...]
- * atomic_read(&nr_ats_masters); pci_enable_ats() // writel()
+ * --- unmap() ---                 --- arm_smmu_enable_ats() ---
+ * TLBI+SYNC                       atomic_inc(&nr_ats_masters);
+ * smp_mb();                       [...]
+ * atomic_read(&nr_ats_masters);   pci_enable_ats() (see writel())
 *
 * Ensures that we always see the incremented 'nr_ats_masters' count if
 * ATS was enabled at the PCI device before completion of the TLBI.
Signature · 1 line
2.34.1
#14 lore raw

Re: [XEN PATCH v3 3/3] xen: fix violations of MISRA C:2012 Rule 3.1

In reply to Luca Fancellu
Quoted 31 lines · Luca Fancellu
Quoted 7 lines · Nicola Vetrini

In the files modified by this patch there are a few occurrences of nested '//' character sequences inside C-style comment blocks, which violate Rule 3.1. The patch aims to resolve those by removing the nested comments.

In the file 'xen/common/xmalloc_tlsf.c' the comment has been replaces by

Typo: s/replaces/replaced/

Quoted 6 lines

an ASSERT, to ensure that the invariant in the comment is enforced.

In the file 'xen/include/xen/atomic.h' the nested comment has been removed, since the code sample is already explained by the preceding comment.

Same as patch 2, missing “---"

Quoted 12 lines

Changes:
- Resending the patch with the right maintainers in CC. Changes in V2:
- Split the patch into a series and reworked the fix;
- Apply the fix to the arm32 `flushtlb.h' file, for consistency. Changes in V3:
- Replaced commmented-out 'if' with an ASSERT( *fl >= 0 ).
---
xen/common/xmalloc_tlsf.c | 4 +--- xen/include/xen/atomic.h | 2 +-

2 files changed, 2 insertions(+), 4 deletions(-)
Quoted 15 lines

xen/common/xmalloc_tlsf.c static inline void MAPPING_SEARCH(unsigned long *r, int *fl, int *sl) · line 143

Quoted 12 lines
xen/common/xmalloc_tlsf.c +1 -3
index 75bdf18c4e..95affcc571 100644
@@ -140,9 +140,7 @@ static inline void MAPPING_SEARCH(unsigned long *r, int *fl, int *sl)
        *fl = flsl(*r) - 1;
        *sl = (*r >> (*fl - MAX_LOG2_SLI)) - MAX_SLI;
        *fl -= FLI_OFFSET;
-        /*if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
-         *fl = *sl = 0;
-         */
+        ASSERT( *fl >= 0 );

I’ve checked the codebase for usage of ASSERT, but I’ve not seen use of it with spaces before and after the condition (like our if conditions) so I think they can be dropped.

Yes, that's right. I am OK with this patch but I think we should wait for Jan's ack to be sure.

An alternative that I feel more comfortable in Acking myself because it doesn't change the semantics of this code would be to change the 3 lines of code above with this:

/*
* ; FL will be always >0!
* if ((*fl -= FLI_OFFSET) < 0)
* fl = *sl = 0;
*/

#5 lore raw

Re: [XEN PATCH v3 1/3] xen/arch/arm: fix violations of MISRA C:2012 Rule 3.1

In reply to Stefano Stabellini

Hi,

Quoted 18 lines · Stefano Stabellini
Quoted 17 lines · Luca Fancellu
Quoted 8 lines · Nicola Vetrini

In the files `xen/arch/arm/include/asm/arm(32|64)/flushtlb.h' there are a few occurrences of nested '//' character sequences inside C-style comment blocks, which violate Rule 3.1. The patch aims to resolve those by changing the inner comments to arm asm comments, delimited by ';' instead.

Can I suggest another commit title:
“xen/arm: tlbflush: fix violations of MISRA C:2012 Rule 3.1"

Sometimes when I am not sure on how to deal with prefixes, I check to the git history of the line I am changing, for these lines there was a commit from Julien using these prefixes. I’m using vs code with GitLens extension, that ease a lot this kind of checks.

Quoted 7 lines
Quoted 3 lines

Apart from that, the changes looks good to me:

With Luca's suggestion (can be done on commit):

I have committed this patch.

Patch #2 requires an ack from Rahul/Bertrand.

Cheers,

Signature · 1 line
Julien Grall
#15 lore raw

Re: [XEN PATCH v3 3/3] xen: fix violations of MISRA C:2012 Rule 3.1

In reply to Stefano Stabellini
Quoted 59 lines · Stefano Stabellini
Quoted 31 lines · Luca Fancellu
Quoted 7 lines · Nicola Vetrini

In the files modified by this patch there are a few occurrences of nested '//' character sequences inside C-style comment blocks, which violate Rule 3.1. The patch aims to resolve those by removing the nested comments.

In the file 'xen/common/xmalloc_tlsf.c' the comment has been replaces by

Typo: s/replaces/replaced/

Quoted 6 lines

an ASSERT, to ensure that the invariant in the comment is enforced.

In the file 'xen/include/xen/atomic.h' the nested comment has been removed, since the code sample is already explained by the preceding comment.

Same as patch 2, missing “---"

Quoted 12 lines

Changes:
- Resending the patch with the right maintainers in CC. Changes in V2:
- Split the patch into a series and reworked the fix;
- Apply the fix to the arm32 `flushtlb.h' file, for consistency. Changes in V3:
- Replaced commmented-out 'if' with an ASSERT( *fl >= 0 ).
---
xen/common/xmalloc_tlsf.c | 4 +--- xen/include/xen/atomic.h | 2 +-

2 files changed, 2 insertions(+), 4 deletions(-)
Quoted 15 lines

xen/common/xmalloc_tlsf.c static inline void MAPPING_SEARCH(unsigned long *r, int *fl, int *sl) · line 143

Quoted 12 lines
xen/common/xmalloc_tlsf.c +1 -3
index 75bdf18c4e..95affcc571 100644
@@ -140,9 +140,7 @@ static inline void MAPPING_SEARCH(unsigned long *r, int *fl, int *sl)
       *fl = flsl(*r) - 1;
       *sl = (*r >> (*fl - MAX_LOG2_SLI)) - MAX_SLI;
       *fl -= FLI_OFFSET;
-        /*if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
-         *fl = *sl = 0;
-         */
+        ASSERT( *fl >= 0 );

I’ve checked the codebase for usage of ASSERT, but I’ve not seen use of it with spaces before and after the condition (like our if conditions) so I think they can be dropped.

Yes, that's right. I am OK with this patch but I think we should wait for Jan's ack to be sure.

An alternative that I feel more comfortable in Acking myself because it doesn't change the semantics of this code would be to change the 3 lines of code above with this:

Quoted 5 lines

/*
* ; FL will be always >0!
* if ((*fl -= FLI_OFFSET) < 0)
* fl = *sl = 0;
*/

Hi Stefano,

I think we would have a violation for the Directive 4.4 (Sections of code should not be commented out) in this case, however it’s not listed in rules.rst and I don’t remember where to look to know if it was taken into consideration for the adoption in Xen in the “tailoring” phase.

#9 lore raw

Re: [XEN PATCH v3 2/3] xen/drivers/passthrough/arm/smmu-v3.c: fix violations of MISRA C:2012 Rule 3.1

In reply to Luca Fancellu
Quoted 15 lines · Luca Fancellu
Quoted 5 lines · Nicola Vetrini

In the file `xen/drivers/passthrough/arm/smmu-v3.c' there are a few occurrences

here you use a different character to enclose the file path (` vs ‘) may I suggest to use only (‘)?

Quoted 6 lines

of nested '//' character sequences inside C-style comment blocks, which violate Rule 3.1.

The patch aims to resolve those by replacing the nested comments with equivalent constructs that do not violate the rule.

Quoted 7 lines
Quoted 1 line

You are missing the “---“ here, meaning that the lines below are part of the commit message and I’m sure you don’t want that.

Also here, may I suggest to use this commit title instead? “xen/arm: smmuv3: Fix violations of MISRA C:2012 Rule 3.1”

Just to mention it: Personally I'm averse to such double subject prefixes. Why would (here) "xen/smmuv3: " not be sufficient (and entirely unambiguous)?

Jan

#16 lore raw

Re: [XEN PATCH v3 3/3] xen: fix violations of MISRA C:2012 Rule 3.1

In reply to Stefano Stabellini
Quoted 23 lines · Stefano Stabellini
Quoted 6 lines · Luca Fancellu
Quoted 6 lines · Nicola Vetrini
xen/common/xmalloc_tlsf.c +0 -0
@@ -140,9 +140,7 @@ static inline void MAPPING_SEARCH(unsigned long *r, int *fl, int *sl)
        *fl = flsl(*r) - 1;
        *sl = (*r >> (*fl - MAX_LOG2_SLI)) - MAX_SLI;
Quoted 8 lines

xen/common/xmalloc_tlsf.c static inline void MAPPING_SEARCH(unsigned long *r, int *fl, int *sl) · line 143

Quoted 5 lines
xen/common/xmalloc_tlsf.c +1 -3
        *fl -= FLI_OFFSET;
-        /*if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
-         *fl = *sl = 0;
-         */
+        ASSERT( *fl >= 0 );

I’ve checked the codebase for usage of ASSERT, but I’ve not seen use of it with spaces before and after the condition (like our if conditions) so I think they can be dropped.

Yes, that's right. I am OK with this patch but I think we should wait for Jan's ack to be sure.

An alternative that I feel more comfortable in Acking myself because it doesn't change the semantics of this code would be to change the 3 lines of code above with this:

Quoted 5 lines

/*
* ; FL will be always >0!
* if ((*fl -= FLI_OFFSET) < 0)
* fl = *sl = 0;
*/

While I'd be okay with this form, as Luca says it'll get us a different violation, which we ought to avoid. While I was the one to suggest the conversion to ASSERT(), having thought about it yet once more I'm now of the opinion that _any_ transformation of this commented out piece of code needs first understanding what was originally meant. Or alternatively, while converting to #if form, to add a comment making crystal clear that it's simply uncertain what was meant.

Jan

Acked-by
#10 lore raw

Re: [XEN PATCH v3 2/3] xen/drivers/passthrough/arm/smmu-v3.c: fix violations of MISRA C:2012 Rule 3.1

In reply to Jan Beulich

Hi,

Quoted 20 lines · Jan Beulich
Quoted 17 lines · Luca Fancellu
Quoted 5 lines · Nicola Vetrini

In the file `xen/drivers/passthrough/arm/smmu-v3.c' there are a few occurrences

here you use a different character to enclose the file path (` vs ‘) may I suggest to use only (‘)?

Quoted 7 lines

of nested '//' character sequences inside C-style comment blocks, which violate Rule 3.1.

The patch aims to resolve those by replacing the nested comments with equivalent constructs that do not violate the rule.

Quoted 8 lines
Quoted 5 lines

You are missing the “---“ here, meaning that the lines below are part of the commit message and I’m sure you don’t want that.

Also here, may I suggest to use this commit title instead? “xen/arm: smmuv3: Fix violations of MISRA C:2012 Rule 3.1”

Just to mention it: Personally I'm averse to such double subject prefixes. Why would (here) "xen/smmuv3: " not be sufficient (and entirely unambiguous)?

With the changes suggested above.

Regards,
Rahul

#11 lore raw

Re: [XEN PATCH v3 2/3] xen/drivers/passthrough/arm/smmu-v3.c: fix violations of MISRA C:2012 Rule 3.1

Hi Rahul,

Quoted 23 lines · Rahul Singh
Quoted 23 lines · Jan Beulich
Quoted 20 lines · Luca Fancellu
Quoted 5 lines · Nicola Vetrini

In the file `xen/drivers/passthrough/arm/smmu-v3.c' there are a few occurrences

here you use a different character to enclose the file path (` vs ‘) may I suggest to use only (‘)?

Quoted 7 lines

of nested '//' character sequences inside C-style comment blocks, which violate Rule 3.1.

The patch aims to resolve those by replacing the nested comments with equivalent constructs that do not violate the rule.

You are missing the “---“ here, meaning that the lines below are part of the commit message and I’m sure you don’t want that.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Also here, may I suggest to use this commit title instead? “xen/arm: smmuv3: Fix violations of MISRA C:2012 Rule 3.1”

Just to mention it: Personally I'm averse to such double subject prefixes. Why would (here) "xen/smmuv3: " not be sufficient (and entirely unambiguous)?

With the changes suggested above.

There are conflicting suggestions about the title. So it is not clear to me which one you are referring to.

I will assume you were happy either way and so picked Luca's proposal and committed.

Quoted 7 lines

Regards,
Rahul

Signature · 1 line
Julien Grall
#17 lore raw

Re: [XEN PATCH v3 3/3] xen: fix violations of MISRA C:2012 Rule 3.1

In reply to Jan Beulich
Quoted 30 lines · Jan Beulich
Quoted 23 lines · Stefano Stabellini
Quoted 6 lines · Luca Fancellu
Quoted 6 lines · Nicola Vetrini
xen/common/xmalloc_tlsf.c +0 -0
@@ -140,9 +140,7 @@ static inline void MAPPING_SEARCH(unsigned long *r, int *fl, int *sl)
         *fl = flsl(*r) - 1;
         *sl = (*r >> (*fl - MAX_LOG2_SLI)) - MAX_SLI;
Quoted 8 lines

xen/common/xmalloc_tlsf.c static inline void MAPPING_SEARCH(unsigned long *r, int *fl, int *sl) · line 143

Quoted 5 lines
xen/common/xmalloc_tlsf.c +1 -3
         *fl -= FLI_OFFSET;
-        /*if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
-         *fl = *sl = 0;
-         */
+        ASSERT( *fl >= 0 );

I’ve checked the codebase for usage of ASSERT, but I’ve not seen use of it with spaces before and after the condition (like our if conditions) so I think they can be dropped.

Yes, that's right. I am OK with this patch but I think we should wait for Jan's ack to be sure.

An alternative that I feel more comfortable in Acking myself because it doesn't change the semantics of this code would be to change the 3 lines of code above with this:

Quoted 5 lines

/*
* ; FL will be always >0!
* if ((*fl -= FLI_OFFSET) < 0)
* fl = *sl = 0;
*/

Quoted 8 lines

While I'd be okay with this form, as Luca says it'll get us a different violation, which we ought to avoid. While I was the one to suggest the conversion to ASSERT(), having thought about it yet once more I'm now of the opinion that _any_ transformation of this commented out piece of code needs first understanding what was originally meant. Or alternatively, while converting to #if form, to add a comment making crystal clear that it's simply uncertain what was meant.

About the violation of D4.4: the Directive was never considered for compliance because it's an advisory directive, and hence considerably less urgent.

Having looked a bit at the surrounding code, since *fl and *sl are used
as array indices later in 'FIND_SUITABLE_BLOCK', I suggest using something along the lines of "If *fl ever becomes < 0, reset it to a safe value." (either using the form suggested by Stefano or an #if 0).

In any case this should become a standalone patch, right?

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

Re: [XEN PATCH v3 3/3] xen: fix violations of MISRA C:2012 Rule 3.1

Quoted 40 lines · Nicola Vetrini
Quoted 30 lines · Jan Beulich
Quoted 23 lines · Stefano Stabellini
Quoted 6 lines · Luca Fancellu
Quoted 6 lines · Nicola Vetrini
xen/common/xmalloc_tlsf.c +0 -0
@@ -140,9 +140,7 @@ static inline void MAPPING_SEARCH(unsigned long *r, int *fl, int *sl)
         *fl = flsl(*r) - 1;
         *sl = (*r >> (*fl - MAX_LOG2_SLI)) - MAX_SLI;
Quoted 8 lines

xen/common/xmalloc_tlsf.c static inline void MAPPING_SEARCH(unsigned long *r, int *fl, int *sl) · line 143

Quoted 5 lines
xen/common/xmalloc_tlsf.c +1 -3
         *fl -= FLI_OFFSET;
-        /*if ((*fl -= FLI_OFFSET) < 0) // FL will be always >0!
-         *fl = *sl = 0;
-         */
+        ASSERT( *fl >= 0 );

I’ve checked the codebase for usage of ASSERT, but I’ve not seen use of it with spaces before and after the condition (like our if conditions) so I think they can be dropped.

Yes, that's right. I am OK with this patch but I think we should wait for Jan's ack to be sure.

An alternative that I feel more comfortable in Acking myself because it doesn't change the semantics of this code would be to change the 3 lines of code above with this:

Quoted 5 lines

/*
* ; FL will be always >0!
* if ((*fl -= FLI_OFFSET) < 0)
* fl = *sl = 0;
*/

Quoted 8 lines

While I'd be okay with this form, as Luca says it'll get us a different violation, which we ought to avoid. While I was the one to suggest the conversion to ASSERT(), having thought about it yet once more I'm now of the opinion that _any_ transformation of this commented out piece of code needs first understanding what was originally meant. Or alternatively, while converting to #if form, to add a comment making crystal clear that it's simply uncertain what was meant.

Quoted 8 lines

About the violation of D4.4: the Directive was never considered for compliance because it's an advisory directive, and hence considerably less urgent.

Having looked a bit at the surrounding code, since *fl and *sl are used as array indices later in 'FIND_SUITABLE_BLOCK', I suggest using something along the lines of "If *fl ever becomes < 0, reset it to a safe value." (either using the form suggested by Stefano or an #if 0).

The main issue I see with any such transformation is how the immediately preceding "*fl -= FLI_OFFSET;" is intended to interact with the commented out code. My gut feeling (but nothing else) says that what was meant would have been

#if 1
        *fl -= FLI_OFFSET;
#else
        if ((*fl -= FLI_OFFSET) < 0) /* FL will be always >0! */
            *fl = *sl = 0;

#endif

But of course without properly understanding the logic it might also have been

        *fl -= FLI_OFFSET;
#if 0
        if ((*fl -= FLI_OFFSET) < 0) /* FL will be always >0! */
            *fl = *sl = 0;

#endif

Quoted 1 line

In any case this should become a standalone patch, right?

Preferably, yes.

Jan