x86/MCE: adjust ID2COOKIE() for Misra C:2012 rule 11.2
PATCH 1/1 x86/MCE: adjust ID2COOKIE() for Misra C:2012 rule 11.2
... ("Conversions shall not be performed between a pointer to an incomplete type and any other type"): Add an intermediate cat to void *.
---
https://gitlab.com/xen-project/hardware/xen-staging/-/jobs/14351897188
(covering more than just this)
xen/arch/x86/cpu/mcheck/mce.c +1 -1
@@ -1264,7 +1264,7 @@ static void cf_check __maybe_unused x86_#if BITS_PER_LONG ==64 -#define ID2COOKIE (id) ((mctelem_cookie_t)(id)) +#define ID2COOKIE (id) ((mctelem_cookie_t)(void *)(id))#define COOKIE2ID (c) ((uint64_t)(c))#elif defined(BITS_PER_LONG )
Quoted 2 lines · Jan Beulich
... ("Conversions shall not be performed between a pointer to an incomplete type and any other type"): Add an intermediate cat to void *.
cast
xen/arch/x86/cpu/mcheck/mce.c static void cf_check __maybe_unused x86_ · line 1267
Quoted 13 lines
Signed-off-by Jan Beulich <[email protected]>---
https://gitlab.com/xen-project/hardware/xen-staging/-/jobs/14351897188
(covering more than just this)xen/arch/x86/cpu/mcheck/mce.c +1
-1@@ -1264,7 +1264,7 @@ static void cf_check __maybe_unused x86_#if BITS_PER_LONG ==64 -#define ID2COOKIE (id) ((mctelem_cookie_t)(id)) +#define ID2COOKIE (id) ((mctelem_cookie_t)(void *)(id))
The interface here is horrible, because we're passing a pointer to a uint64_t to userspace and back.
But, can't we just cast through unsigned long instead? The compiler is happy, and that feels safer than using a pointer type.
~Andrew
Quoted 5 lines · Andrew Cooper
Quoted 4 lines · Jan Beulich
xen/arch/x86/cpu/mcheck/mce.c +0
-0@@ -1264,7 +1264,7 @@ static void cf_check __maybe_unused x86_
Quoted 7 lines
xen/arch/x86/cpu/mcheck/mce.c static void cf_check __maybe_unused x86_ · line 1267
Quoted 4 lines
xen/arch/x86/cpu/mcheck/mce.c +1
-1#if BITS_PER_LONG ==64 -#define ID2COOKIE (id) ((mctelem_cookie_t)(id)) +#define ID2COOKIE (id) ((mctelem_cookie_t)(void *)(id))The interface here is horrible, because we're passing a pointer to a
uint64_tto userspace and back.
Indeed.
Quoted 2 lines
But, can't we just cast through unsigned long instead? The compiler is happy, and that feels safer than using a pointer type.
I can check if that also helps. Casting to void * let's us, aiui, get away without leveraging any custom deviations that we have.
Jan
Quoted 17 lines · Andrew Cooper
Quoted 2 lines · Jan Beulich
... ("Conversions shall not be performed between a pointer to an incomplete type and any other type"): Add an intermediate cat to void *.
cast
Quoted 11 lines
Signed-off-by Jan Beulich <[email protected]>---
https://gitlab.com/xen-project/hardware/xen-staging/-/jobs/14351897188
(covering more than just this)xen/arch/x86/cpu/mcheck/mce.c +0
-0@@ -1264,7 +1264,7 @@ static void cf_check __maybe_unused x86_#if BITS_PER_LONG ==64
Quoted 8 lines
xen/arch/x86/cpu/mcheck/mce.c static void cf_check __maybe_unused x86_ · line 1267
Quoted 2 lines
xen/arch/x86/cpu/mcheck/mce.c +1
-1-#define ID2COOKIE (id) ((mctelem_cookie_t)(id)) +#define ID2COOKIE (id) ((mctelem_cookie_t)(void *)(id))The interface here is horrible, because we're passing a pointer to a
uint64_tto userspace and back.But, can't we just cast through unsigned long instead? The compiler is happy, and that feels safer than using a pointer type.
As per https://gitlab.com/xen-project/hardware/xen-staging/-/jobs/14416863057
that doesn't work.
Jan
Quoted 11 lines · Jan Beulich
... ("Conversions shall not be performed between a pointer to an incomplete type and any other type"): Add an intermediate cat to void *.
Signed-off-by Jan Beulich <[email protected]>---
https://gitlab.com/xen-project/hardware/xen-staging/-/jobs/14351897188
(covering more than just this)
xen/arch/x86/cpu/mcheck/mce.c static void cf_check __maybe_unused x86_ · line 1267
Quoted 5 lines
xen/arch/x86/cpu/mcheck/mce.c +1
-1@@ -1264,7 +1264,7 @@ static void cf_check __maybe_unused x86_#if BITS_PER_LONG ==64 -#define ID2COOKIE (id) ((mctelem_cookie_t)(id)) +#define ID2COOKIE (id) ((mctelem_cookie_t)(void *)(id))
Notwithstanding the comment from Andrew, I think a comment here could be nice to explain what it going on, otherwise the double cast looks quite odd.
Unrelated: why not contextually marking this rule as clean to prevent regressions?
Quoted 3 lines
xen/arch/x86/cpu/mcheck/mce.c +0
-0#define COOKIE2ID (c) ((uint64_t)(c))#elif defined(BITS_PER_LONG )
Signature · 4 lines
Nicola Vetrini, B.Sc. Software Engineer BUGSENG (https://bugseng.com) LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
Quoted 14 lines · Nicola Vetrini
Quoted 13 lines · Jan Beulich
... ("Conversions shall not be performed between a pointer to an incomplete type and any other type"): Add an intermediate cat to void *.
Signed-off-by Jan Beulich <[email protected]>---
https://gitlab.com/xen-project/hardware/xen-staging/-/jobs/14351897188
(covering more than just this)xen/arch/x86/cpu/mcheck/mce.c +0
-0@@ -1264,7 +1264,7 @@ static void cf_check __maybe_unused x86_
Quoted 8 lines
xen/arch/x86/cpu/mcheck/mce.c static void cf_check __maybe_unused x86_ · line 1267
Quoted 4 lines
xen/arch/x86/cpu/mcheck/mce.c +1
-1#if BITS_PER_LONG ==64 -#define ID2COOKIE (id) ((mctelem_cookie_t)(id)) +#define ID2COOKIE (id) ((mctelem_cookie_t)(void *)(id))Notwithstanding the comment from Andrew, I think a comment here could be nice to explain what it going on, otherwise the double cast looks quite odd.
I've added
/* Two layers of casting to cover Misra C:2012 rule 11.2. */
Quoted 2 lines
Unrelated: why not contextually marking this rule as clean to prevent regressions?
Isn't this rule (and the others my patches were targeting) marked as clean already, hence why the allcode job fails?
Jan
Quoted 24 lines · Jan Beulich
Quoted 14 lines · Nicola Vetrini
Quoted 13 lines · Jan Beulich
... ("Conversions shall not be performed between a pointer to an incomplete type and any other type"): Add an intermediate cat to void *.
Signed-off-by Jan Beulich <[email protected]>---
https://gitlab.com/xen-project/hardware/xen-staging/-/jobs/14351897188
(covering more than just this)xen/arch/x86/cpu/mcheck/mce.c +0
-0@@ -1264,7 +1264,7 @@ static void cf_check __maybe_unused x86_Quoted 8 lines
xen/arch/x86/cpu/mcheck/mce.c static void cf_check __maybe_unused x86_ · line 1267
Quoted 4 lines
xen/arch/x86/cpu/mcheck/mce.c +1
-1#if BITS_PER_LONG ==64 -#define ID2COOKIE (id) ((mctelem_cookie_t)(id)) +#define ID2COOKIE (id) ((mctelem_cookie_t)(void *)(id))Notwithstanding the comment from Andrew, I think a comment here could be nice to explain what it going on, otherwise the double cast looks quite odd.
Quoted 4 lines
I've added
/* Two layers of casting to cover Misra C:2012 rule 11.2. */
Sounds good
Quoted 6 lines
Quoted 2 lines
Unrelated: why not contextually marking this rule as clean to prevent regressions?
Isn't this rule (and the others my patches were targeting) marked as clean already, hence why the allcode job fails?
Oh, you are right, I didn't check.
Signature · 4 lines
Nicola Vetrini, B.Sc. Software Engineer BUGSENG (https://bugseng.com) LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253