[PATCH v2] xen/arm: deviate MISRA R11.8 for capability enable callbacks

Dmytro Prokopchuk1 posted 1 patch 4 days, 10 hours ago
docs/misra/safe.json      | 8 ++++++++
xen/arch/arm/cpufeature.c | 2 ++
2 files changed, 10 insertions(+)
[PATCH v2] xen/arm: deviate MISRA R11.8 for capability enable callbacks
Posted by Dmytro Prokopchuk1 4 days, 10 hours ago
MISRA C Rule 11.8 forbids casts that remove the const qualifier from
the pointed-to type. enable_cpu_capabilities() and
enable_nonboot_cpu_caps() cast a const struct arm_cpu_capabilities
pointer to void * so that it can be passed to the capability enable
callback, either directly or through stop_machine_run().

The callback type takes void * by convention. Existing callback
implementations treat the pointer as const and do not modify the
object. Document both casts with SAF-15-safe comment.

No functional changes.

Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com>
---
Changes in v2:
- make SAF-15 generic for casting a const pointer to void * for a
  callback, not Arm caps only
---
 docs/misra/safe.json      | 8 ++++++++
 xen/arch/arm/cpufeature.c | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/docs/misra/safe.json b/docs/misra/safe.json
index 3584cb90c6..85a2f31692 100644
--- a/docs/misra/safe.json
+++ b/docs/misra/safe.json
@@ -124,6 +124,14 @@
         },
         {
             "id": "SAF-15-safe",
+            "analyser": {
+                "eclair": "MC3A2.R11.8"
+            },
+            "name": "Rule 11.8: cast const pointer to void * for a callback",
+            "text": "Callbacks often have void * parameters, to be type-generic. Casting a const-qualified pointer to void * only to pass it into such a signature is safe when the callback implementation treat the pointer as const and do not modify the object."
+        },
+        {
+            "id": "SAF-16-safe",
             "analyser": {},
             "name": "Sentinel",
             "text": "Next ID to be used"
diff --git a/xen/arch/arm/cpufeature.c b/xen/arch/arm/cpufeature.c
index 8d8cd19a96..7db0f8dcdb 100644
--- a/xen/arch/arm/cpufeature.c
+++ b/xen/arch/arm/cpufeature.c
@@ -72,6 +72,7 @@ void __init enable_cpu_capabilities(const struct arm_cpu_capabilities *caps)
              * an IPI, giving us a PSTATE that disappears when we
              * return.
              */
+            /* SAF-15-safe R11.8 cast const pointer to void * for a callback */
             ret = stop_machine_run(caps->enable, (void *)caps, NR_CPUS);
             /* stop_machine_run should never fail at this stage of the boot. */
             BUG_ON(ret);
@@ -108,6 +109,7 @@ int enable_nonboot_cpu_caps(const struct arm_cpu_capabilities *caps)
 
         if ( caps->enable )
         {
+            /* SAF-15-safe R11.8 cast const pointer to void * for a callback */
             int ret = caps->enable((void *)caps);
 
             if ( ret )
-- 
2.43.0
Re: [PATCH v2] xen/arm: deviate MISRA R11.8 for capability enable callbacks
Posted by Jan Beulich 4 days, 10 hours ago
On 19.11.2026 12:49, Dmytro Prokopchuk1 wrote:
> MISRA C Rule 11.8 forbids casts that remove the const qualifier from
> the pointed-to type. enable_cpu_capabilities() and
> enable_nonboot_cpu_caps() cast a const struct arm_cpu_capabilities
> pointer to void * so that it can be passed to the capability enable
> callback, either directly or through stop_machine_run().
> 
> The callback type takes void * by convention. Existing callback
> implementations treat the pointer as const and do not modify the
> object. Document both casts with SAF-15-safe comment.
> 
> No functional changes.
> 
> Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com>

Acked-by: Jan Beulich <jbeulich@suse.com>