[PATCH v2] x86/MCE: adjust ID2COOKIE() for Misra C:2012 rule 11.2

Jan Beulich posted 1 patch 5 days, 10 hours ago
Failed in applying to current master (apply log)
[PATCH v2] x86/MCE: adjust ID2COOKIE() for Misra C:2012 rule 11.2
Posted by Jan Beulich 5 days, 10 hours ago
... ("Conversions shall not be performed between a pointer to an
incomplete type and any other type"): Add an intermediate cast to
unsigned long.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
v2: Add comment.

--- a/xen/arch/x86/cpu/mcheck/mce.c
+++ b/xen/arch/x86/cpu/mcheck/mce.c
@@ -1264,7 +1264,8 @@ static void cf_check __maybe_unused x86_
 
 #if BITS_PER_LONG == 64
 
-#define ID2COOKIE(id) ((mctelem_cookie_t)(id))
+/* Two layers of casting to cover Misra C:2012 rule 11.2. */
+#define ID2COOKIE(id) ((mctelem_cookie_t)(void *)(id))
 #define COOKIE2ID(c) ((uint64_t)(c))
 
 #elif defined(BITS_PER_LONG)
Re: [PATCH v2] x86/MCE: adjust ID2COOKIE() for Misra C:2012 rule 11.2
Posted by Nicola Vetrini 5 days, 5 hours ago
On 2026-05-18 11:51, Jan Beulich wrote:
> ... ("Conversions shall not be performed between a pointer to an
> incomplete type and any other type"): Add an intermediate cast to
> unsigned long.
> 

Stale comment I presume.

> Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
> ---
> v2: Add comment.
> 
> --- a/xen/arch/x86/cpu/mcheck/mce.c
> +++ b/xen/arch/x86/cpu/mcheck/mce.c
> @@ -1264,7 +1264,8 @@ static void cf_check __maybe_unused x86_
> 
>  #if BITS_PER_LONG == 64
> 
> -#define ID2COOKIE(id) ((mctelem_cookie_t)(id))
> +/* Two layers of casting to cover Misra C:2012 rule 11.2. */
> +#define ID2COOKIE(id) ((mctelem_cookie_t)(void *)(id))
>  #define COOKIE2ID(c) ((uint64_t)(c))
> 
>  #elif defined(BITS_PER_LONG)

-- 
Nicola Vetrini, B.Sc.
Software Engineer
BUGSENG (https://bugseng.com)
LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
Re: [PATCH v2] x86/MCE: adjust ID2COOKIE() for Misra C:2012 rule 11.2
Posted by Jan Beulich 5 days, 5 hours ago
On 18.05.2026 16:35, Nicola Vetrini wrote:
> On 2026-05-18 11:51, Jan Beulich wrote:
>> ... ("Conversions shall not be performed between a pointer to an
>> incomplete type and any other type"): Add an intermediate cast to
>> unsigned long.
> 
> Stale comment I presume.

Indeed, forgot to edit it again after the failed attempt.

>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> Reviewed-by: Nicola Vetrini <nicola.vetrini@bugseng.com>

Thanks.

Jan