Skip to contentSkip to conversation

misra: add Rule 5.5 deviations for intentional macro clashes

PATCH Superseded Dmytro Prokopchuk1 3 participants 7 messages May 25 – Jun 4

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#1 lore raw

PATCH 1/3 misra: deviate MISRA C Rule 5.5 for 'hypfs_alloc_dyndata'

In reply to Dmytro Prokopchuk1

MISRA C Rule 5.5 states: "Identifiers shall be distinct from macro names".

Update ECLAIR configuration to deviate intentional identifier and macro name clashes by specifying the macros that should be ignored. This includes 'hypfs_alloc_dyndata', where the real function takes an allocation size and the same-named macro is a typed convenience wrapper that expands calls using sizeof(type).

Update deviations.rst and rules.rst accordingly.

---
 automation/eclair_analysis/ECLAIR/deviations.ecl | 6 ++++++
 docs/misra/deviations.rst                        | 9 +++++++++
 docs/misra/rules.rst                             | 4 ++++
 3 files changed, 19 insertions(+)
automation/eclair_analysis/ECLAIR/deviations.ecl +6 -0
index 7d4b6f2948..13a34b7703 100644
@@ -132,6 +132,12 @@ These macros address differences in argument count during compile-time, effectiv
 -config=MC3A2.R5.5,ignored_macros+="name(update_gnttab_par||parse_gnttab_limit)&&loc(file(^xen/common/grant_table\\.c$))"
 -doc_end
 
+-doc_begin="Clash between 'hypfs_alloc_dyndata' function and macro name in 'xen/include/xen/hypfs.h' is deliberate.
+The function is the allocator taking a size in bytes, while the macro is a typed convenience wrapper used by dynamic
+hypfs nodes to allocate per-request traversal data with the correct size and return type."
+-config=MC3A2.R5.5,ignored_macros+="name(hypfs_alloc_dyndata)&&loc(file(^xen/include/xen/hypfs\\.h$))"
+-doc_end
+
 -doc_begin="The type \"ret_t\" is deliberately defined multiple times,
 depending on the guest."
 -config=MC3A2.R5.6,reports+={deliberate,"any_area(any_loc(text(^.*ret_t.*$)))"}
docs/misra/deviations.rst +9 -0
index b048309596..f5b4ce9315 100644
@@ -176,6 +176,15 @@ Deviations related to MISRA C:2012 Rules:
        unused 2nd and 3rd parameters to avoid warnings or errors related to them.
      - ECLAIR has been configured to ignore these macros.
 
+   * - R5.5
+     - Clash between the 'hypfs_alloc_dyndata' function and macro name is
+       intentional. The function is the allocator taking a size in bytes, while
+       the macro is a typed convenience wrapper used by dynamic hypfs nodes to
+       allocate per-request traversal data with the correct size and return type.
+       The implementation explicitly undefines the macro before defining the real
+       function, so the name clash is controlled.
+     - ECLAIR has been configured to ignore this macro.
+
    * - R5.6
      - The type ret_t is deliberately defined multiple times depending on the
        type of guest to service.
docs/misra/rules.rst +4 -0
index b3e929307d..c0237725a9 100644
@@ -222,6 +222,10 @@ maintainers if you want to suggest a change.
        Clashes between grant table functions and macro names are allowed
        because they are used for discarding unused parameters.
 
+       Clash between hypfs_alloc_dyndata function and macro names is allowed
+       because the macro is a typed convenience wrapper around the size-based
+       allocation function.
+
    * - `Rule 5.6 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_05_06.c>`_
      - Required
      - A typedef name shall be a unique identifier
Signature · 1 line
2.43.0
#5 lore raw

PATCH 3/3 misra: deviate MISRA C Rule 5.5 for ARM SMMU fault handlers

In reply to Dmytro Prokopchuk1

MISRA C Rule 5.5 states: "Identifiers shall be distinct from macro names".

Update ECLAIR configuration to deviate intentional identifier and macro name clashes by specifying the macros that should be ignored. This includes 'arm_smmu_global_fault' and 'arm_smmu_context_fault', where the original ARM SMMU handler returns irqreturn_t, while the same-named macro redirects later uses to a Xen wrapper with the void interrupt-handler signature expected by Xen 'request_irq()'.

Update deviations.rst and rules.rst accordingly.

---
 automation/eclair_analysis/ECLAIR/deviations.ecl | 6 ++++++
 docs/misra/deviations.rst                        | 7 +++++++
 docs/misra/rules.rst                             | 4 ++++
 3 files changed, 17 insertions(+)
automation/eclair_analysis/ECLAIR/deviations.ecl +6 -0
index 7aa64796ba..419a23ce8e 100644
@@ -144,6 +144,12 @@ ARM SMMU driver calls by reordering the handler and flags arguments."
 -config=MC3A2.R5.5,ignored_macros+="name(request_irq)&&loc(file(^xen/drivers/passthrough/arm/smmu\\.c$))"
 -doc_end
 
+-doc_begin="Clashes between ARM SMMU fault handler functions and macro names in 'xen/drivers/passthrough/arm/smmu.c' are deliberate.
+The original ARM SMMU handler returns irqreturn_t, while the macro redirects later uses to a Xen wrapper with the
+void interrupt-handler signature expected by Xen 'request_irq()'."
+-config=MC3A2.R5.5,ignored_macros+="name(arm_smmu_global_fault||arm_smmu_context_fault)&&loc(file(^xen/drivers/passthrough/arm/smmu\\.c$))"
+-doc_end
+
 -doc_begin="The type \"ret_t\" is deliberately defined multiple times,
 depending on the guest."
 -config=MC3A2.R5.6,reports+={deliberate,"any_area(any_loc(text(^.*ret_t.*$)))"}
docs/misra/deviations.rst +7 -0
index 01f141b73f..15c88b82f4 100644
@@ -192,6 +192,13 @@ Deviations related to MISRA C:2012 Rules:
        reordering the handler and flags arguments.
      - ECLAIR has been configured to ignore this macro.
 
+   * - R5.5
+     - Clashes between the ARM SMMU fault handler functions and macro names are
+       intentional. The original ARM SMMU handler returns irqreturn_t, while
+       the macro redirects later uses to a Xen wrapper with the void
+       interrupt-handler signature expected by Xen 'request_irq()'.
+     - ECLAIR has been configured to ignore these macros.
+
    * - R5.6
      - The type ret_t is deliberately defined multiple times depending on the
        type of guest to service.
docs/misra/rules.rst +4 -0
index 097c20432e..88d2c5fa7c 100644
@@ -230,6 +230,10 @@ maintainers if you want to suggest a change.
        the macro is a local compatibility wrapper that adapts ARM SMMU driver
        call to Xen's request_irq() argument order.
 
+       Clashes between ARM SMMU fault handler functions and macro names are
+       allowed because the macros redirect ARM SMMU driver uses to a Xen interrupt
+       wrapper with the handler signature expected by request_irq().
+
    * - `Rule 5.6 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_05_06.c>`_
      - Required
      - A typedef name shall be a unique identifier
Signature · 1 line
2.43.0
#0 lore raw

cover misra: add Rule 5.5 deviations for intentional macro clashes

This series adds deviations for intentional function/macro name clashes where the macro is used as a wrapper around an existing function name.

Test CI pipeline:
https://gitlab.com/xen-project/people/dimaprkp4k/xen/-/pipelines/2550931948

Dmytro Prokopchuk (3):
misra: deviate MISRA C Rule 5.5 for 'hypfs_alloc_dyndata'
misra: deviate MISRA C Rule 5.5 for 'request_irq'
misra: deviate MISRA C Rule 5.5 for ARM SMMU fault handlers

 .../eclair_analysis/ECLAIR/deviations.ecl     | 18 +++++++++++++++
 docs/misra/deviations.rst                     | 23 +++++++++++++++++++
 docs/misra/rules.rst                          | 12 ++++++++++
 3 files changed, 53 insertions(+)
Signature · 1 line
2.43.0
#3 lore raw

PATCH 2/3 misra: deviate MISRA C Rule 5.5 for 'request_irq'

MISRA C Rule 5.5 states: "Identifiers shall be distinct from macro names".

Update ECLAIR configuration to deviate intentional identifier and macro name clashes by specifying the macros that should be ignored. This includes 'request_irq', where the Xen function takes the IRQ flags before the handler argument, while the macro adapts ARM SMMU driver calls by reordering the arguments.

Update deviations.rst and rules.rst accordingly.

---
 automation/eclair_analysis/ECLAIR/deviations.ecl | 6 ++++++
 docs/misra/deviations.rst                        | 7 +++++++
 docs/misra/rules.rst                             | 4 ++++
 3 files changed, 17 insertions(+)
automation/eclair_analysis/ECLAIR/deviations.ecl +6 -0
index 13a34b7703..7aa64796ba 100644
@@ -138,6 +138,12 @@ hypfs nodes to allocate per-request traversal data with the correct size and ret
 -config=MC3A2.R5.5,ignored_macros+="name(hypfs_alloc_dyndata)&&loc(file(^xen/include/xen/hypfs\\.h$))"
 -doc_end
 
+-doc_begin="Clash between 'request_irq' function and macro name in 'xen/drivers/passthrough/arm/smmu.c' is deliberate.
+The function uses the Xen 'request_irq()' argument order, while the macro is a compatibility wrapper that adapts
+ARM SMMU driver calls by reordering the handler and flags arguments."
+-config=MC3A2.R5.5,ignored_macros+="name(request_irq)&&loc(file(^xen/drivers/passthrough/arm/smmu\\.c$))"
+-doc_end
+
 -doc_begin="The type \"ret_t\" is deliberately defined multiple times,
 depending on the guest."
 -config=MC3A2.R5.6,reports+={deliberate,"any_area(any_loc(text(^.*ret_t.*$)))"}
docs/misra/deviations.rst +7 -0
index f5b4ce9315..01f141b73f 100644
@@ -185,6 +185,13 @@ Deviations related to MISRA C:2012 Rules:
        function, so the name clash is controlled.
      - ECLAIR has been configured to ignore this macro.
 
+   * - R5.5
+     - Clash between the 'request_irq' function and macro name is intentional.
+       The function uses the Xen 'request_irq()' argument order, while the macro
+       is a compatibility wrapper for the ARM SMMU driver that adapts calls by
+       reordering the handler and flags arguments.
+     - ECLAIR has been configured to ignore this macro.
+
    * - R5.6
      - The type ret_t is deliberately defined multiple times depending on the
        type of guest to service.
docs/misra/rules.rst +4 -0
index c0237725a9..097c20432e 100644
@@ -226,6 +226,10 @@ maintainers if you want to suggest a change.
        because the macro is a typed convenience wrapper around the size-based
        allocation function.
 
+       Clash between request_irq function and macro names is allowed because
+       the macro is a local compatibility wrapper that adapts ARM SMMU driver
+       call to Xen's request_irq() argument order.
+
    * - `Rule 5.6 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_05_06.c>`_
      - Required
      - A typedef name shall be a unique identifier
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 1/3] misra: deviate MISRA C Rule 5.5 for 'hypfs_alloc_dyndata'

In reply to Dmytro Prokopchuk1
Quoted 9 lines · On 25.05.2026 14:05, Dmytro Prokopchuk1 wrote:

MISRA C Rule 5.5 states: "Identifiers shall be distinct from macro names".

Update ECLAIR configuration to deviate intentional identifier and macro name clashes by specifying the macros that should be ignored. This includes 'hypfs_alloc_dyndata', where the real function takes an allocation size and the same-named macro is a typed convenience wrapper that expands calls using sizeof(type).

Quoted 3 lines

Update deviations.rst and rules.rst accordingly.

While I'm okay with this approach, were alternatives considered? E.g. following the xmalloc() naming model, even if that has a name spacing issue (which ideally we wouldn't further extend)?

automation/eclair_analysis/ECLAIR/deviations.ecl These macros address differences in argument count during compile-time, effectiv · line 139

Quoted 11 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +5 -0
@@ -132,6 +132,12 @@ These macros address differences in argument count during compile-time, effectiv
 -config=MC3A2.R5.5,ignored_macros+="name(update_gnttab_par||parse_gnttab_limit)&&loc(file(^xen/common/grant_table\\.c$))"
 -doc_end
 
+-doc_begin="Clash between 'hypfs_alloc_dyndata' function and macro name in 'xen/include/xen/hypfs.h' is deliberate.
+The function is the allocator taking a size in bytes, while the macro is a typed convenience wrapper used by dynamic
+hypfs nodes to allocate per-request traversal data with the correct size and return type."
+-config=MC3A2.R5.5,ignored_macros+="name(hypfs_alloc_dyndata)&&loc(file(^xen/include/xen/hypfs\\.h$))"
+-doc_end

I think this is too verbose for the purposes here. The details can all be had ...

Quoted 4 lines
docs/misra/deviations.rst +0 -0
@@ -176,6 +176,15 @@ Deviations related to MISRA C:2012 Rules:
        unused 2nd and 3rd parameters to avoid warnings or errors related to them.

docs/misra/deviations.rst Deviations related to MISRA C:2012 Rules: · line 186

Quoted 10 lines
docs/misra/deviations.rst +8 -0
      - ECLAIR has been configured to ignore these macros.
 
+   * - R5.5
+     - Clash between the 'hypfs_alloc_dyndata' function and macro name is
+       intentional. The function is the allocator taking a size in bytes, while
+       the macro is a typed convenience wrapper used by dynamic hypfs nodes to
+       allocate per-request traversal data with the correct size and return type.
+       The implementation explicitly undefines the macro before defining the real
+       function, so the name clash is controlled.
+     - ECLAIR has been configured to ignore this macro.

... from here.

Jan

#4 lore raw

Re: [PATCH 2/3] misra: deviate MISRA C Rule 5.5 for 'request_irq'

In reply to Dmytro Prokopchuk1

automation/eclair_analysis/ECLAIR/deviations.ecl hypfs nodes to allocate per-request traversal data with the correct size and ret · line 141

Quoted 7 lines · On 25.05.2026 14:05, Dmytro Prokopchuk1 wrote:
automation/eclair_analysis/ECLAIR/deviations.ecl +1 -0
@@ -138,6 +138,12 @@ hypfs nodes to allocate per-request traversal data with the correct size and ret
 -config=MC3A2.R5.5,ignored_macros+="name(hypfs_alloc_dyndata)&&loc(file(^xen/include/xen/hypfs\\.h$))"
 -doc_end
 
+-doc_begin="Clash between 'request_irq' function and macro name in 'xen/drivers/passthrough/arm/smmu.c' is deliberate.

While I think "deliberate" is appropriate for the situation, ...

docs/misra/deviations.rst Deviations related to MISRA C:2012 Rules: · line 189

Quoted 8 lines
docs/misra/deviations.rst +2 -0
@@ -185,6 +185,13 @@ Deviations related to MISRA C:2012 Rules:
        function, so the name clash is controlled.
      - ECLAIR has been configured to ignore this macro.
 
+   * - R5.5
+     - Clash between the 'request_irq' function and macro name is intentional.

... imo "intentional" doesn't quite fit: I'm pretty sure we'd prefer to avoid this, but we want to keep the code imported from Linux as tidy of local changes as possible.

docs/misra/deviations.rst Deviations related to MISRA C:2012 Rules: · line 192

Quoted 3 lines
docs/misra/deviations.rst +3 -0
+       The function uses the Xen 'request_irq()' argument order, while the macro
+       is a compatibility wrapper for the ARM SMMU driver that adapts calls by
+       reordering the handler and flags arguments.

Imo this restriction to one particular source file wants (somehow) expressing in the very first sentence already, to avoid the impression that the clash would be acceptable elsewhere as well.

Also, throughout: Please always append () to function (and function-like macro) names. Right now you have a seemingly random mix.

Jan

#6 lore raw

Re: [PATCH 3/3] misra: deviate MISRA C Rule 5.5 for ARM SMMU fault handlers

In reply to Dmytro Prokopchuk1
Quoted 78 lines · On 2026-05-25 14:05, Dmytro Prokopchuk1 wrote:

MISRA C Rule 5.5 states: "Identifiers shall be distinct from macro names".

Update ECLAIR configuration to deviate intentional identifier and macro name clashes by specifying the macros that should be ignored. This includes 'arm_smmu_global_fault' and 'arm_smmu_context_fault', where the original ARM SMMU handler returns irqreturn_t, while the same-named macro redirects later uses to a Xen wrapper with the void interrupt-handler signature expected by Xen 'request_irq()'.

Update deviations.rst and rules.rst accordingly.

---
 automation/eclair_analysis/ECLAIR/deviations.ecl | 6 ++++++
 docs/misra/deviations.rst                        | 7 +++++++
 docs/misra/rules.rst                             | 4 ++++
 3 files changed, 17 insertions(+)
automation/eclair_analysis/ECLAIR/deviations.ecl +0 -0
index 7aa64796ba..419a23ce8e 100644
@@ -144,6 +144,12 @@ ARM SMMU driver calls by reordering the handler 

and flags arguments."

-config=MC3A2.R5.5,ignored_macros+="name(request_irq)&&loc(file(^xen/drivers/passthrough/arm/smmu\\.c$))"
-doc_end

+-doc_begin="Clashes between ARM SMMU fault handler functions and macro names in 'xen/drivers/passthrough/arm/smmu.c' are deliberate. +The original ARM SMMU handler returns irqreturn_t, while the macro redirects later uses to a Xen wrapper with the

automation/eclair_analysis/ECLAIR/deviations.ecl +4 -1
+void interrupt-handler signature expected by Xen 'request_irq()'."
+-config=MC3A2.R5.5,ignored_macros+="name(arm_smmu_global_fault||arm_smmu_context_fault)&&loc(file(^xen/drivers/passthrough/arm/smmu\\.c$))"
+-doc_end
+
 -doc_begin="The type \"ret_t\" is deliberately defined multiple times,
 depending on the guest."
 
-config=MC3A2.R5.6,reports+={deliberate,"any_area(any_loc(text(^.*ret_t.*$)))"}
docs/misra/deviations.rst +2 -0
index 01f141b73f..15c88b82f4 100644
@@ -192,6 +192,13 @@ Deviations related to MISRA C:2012 Rules:
        reordering the handler and flags arguments.
      - ECLAIR has been configured to ignore this macro.
 
+   * - R5.5
+     - Clashes between the ARM SMMU fault handler functions and macro 

names are
+ intentional. The original ARM SMMU handler returns irqreturn_t,
while

docs/misra/deviations.rst +4 -0
+       the macro redirects later uses to a Xen wrapper with the void
+       interrupt-handler signature expected by Xen 'request_irq()'.
+     - ECLAIR has been configured to ignore these macros.
+
    * - R5.6
      - The type ret_t is deliberately defined multiple times depending 

on the
type of guest to service.

docs/misra/rules.rst +0 -0
index 097c20432e..88d2c5fa7c 100644
@@ -230,6 +230,10 @@ maintainers if you want to suggest a change.
        the macro is a local compatibility wrapper that adapts ARM SMMU 

driver
call to Xen's request_irq() argument order.

+ Clashes between ARM SMMU fault handler functions and macro
names are
+ allowed because the macros redirect ARM SMMU driver uses to a
Xen interrupt

docs/misra/rules.rst +2 -0
+       wrapper with the handler signature expected by request_irq().
+
    * - `Rule 5.6 
Quoted 3 lines

<https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_05_06.c>`_
- Required
- A typedef name shall be a unique identifier

Seeing the growing number of exceptions for R5.5 and 5.6 for one reason or another in deviations.ecl, I wonder whether a more structured approach to the configuration would be better (e.g., a JSON file that is then processed just before the build to produce an ECL file fragment evaluated in the the right place). The change itself is fine, but I think this would tidy up a bit the file from these targeted exceptions.

Signature · 4 lines
Nicola Vetrini, B.Sc.
Software Engineer
BUGSENG (https://bugseng.com)
LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253