All of lore.kernel.org
 help / color / mirror / Atom feed
* [XEN PATCH 00/10] address some violations of MISRA C Rule 20.7
@ 2024-03-18 11:53 Nicola Vetrini
  2024-03-18 11:53 ` [XEN PATCH 01/10] x86/cpufeature: add parentheses to comply with " Nicola Vetrini
                   ` (9 more replies)
  0 siblings, 10 replies; 22+ messages in thread
From: Nicola Vetrini @ 2024-03-18 11:53 UTC (permalink / raw)
  To: nicola.vetrini, xen-devel
  Cc: sstabellini, michal.orzel, xenia.ragiadakou, ayan.kumar.halder,
	consulting, Jan Beulich, Andrew Cooper, Roger Pau Monné,
	Wei Liu, Daniel P. Smith, Julien Grall, Rahul Singh,
	Bertrand Marquis, Volodymyr Babchuk, George Dunlap,
	Dario Faggioli

Hi all,

this series aims to refactor some macros that cause violations of MISRA C Rule
20.7 ("Expressions resulting from the expansion of macro parameters shall be
enclosed in parentheses"). All the macros touched by these patches are in some
way involved in violations, and the strategy adopted to bring them into
compliance is to add parentheses around macro arguments where needed.

Given that the community has previously requested a deviation from the rule, as
stated in docs/misra/deviations.rst, and reported below for convenience [1],
some macro parameters do not need any adjusting (e.g., when used as lhs to
an assignment in statement expressions).

Note that the patch on list.h of the earlier series [2] has been intentionally
left out of this series, because it still needs some adjustments.

[1] - Code violating Rule 20.7 is safe when macro parameters are used:
       (1) as function arguments;
       (2) as macro arguments;
       (3) as array indices;
       (4) as lhs in assignments.
       
[2] https://lore.kernel.org/xen-devel/cover.1709896401.git.nicola.vetrini@bugseng.com/

Nicola Vetrini (10):
  x86/cpufeature: add parentheses to comply with Rule 20.7
  AMD/IOMMU: guest: address violations of MISRA C Rule 20.7
  xen/xsm: add parentheses to comply with MISRA C Rule 20.7
  xen/device_tree: address violations of MISRA C Rule 20.7
  EFI: address violations of MISRA C Rule 20.7
  xen/arm: smmu: address violations of MISRA C Rule 20.7
  xen/efi: efibind: address violations of MISRA C Rule 20.7
  xen/notifier: address violations of MISRA C Rule 20.7
  xen/wait: address violations of MISRA C Rule 20.7
  xen/sched: address violations of MISRA C Rule 20.7

 xen/arch/arm/include/asm/arm64/efibind.h  | 4 ++--
 xen/arch/x86/include/asm/cpufeatureset.h  | 2 +-
 xen/arch/x86/include/asm/x86_64/efibind.h | 4 ++--
 xen/common/sched/private.h                | 2 +-
 xen/drivers/passthrough/amd/iommu_guest.c | 2 +-
 xen/drivers/passthrough/arm/smmu.c        | 2 +-
 xen/include/efi/efierr.h                  | 2 +-
 xen/include/xen/device_tree.h             | 2 +-
 xen/include/xen/notifier.h                | 2 +-
 xen/include/xen/wait.h                    | 4 ++--
 xen/include/xsm/dummy.h                   | 4 ++--
 11 files changed, 15 insertions(+), 15 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [XEN PATCH 01/10] x86/cpufeature: add parentheses to comply with Rule 20.7
  2024-03-18 11:53 [XEN PATCH 00/10] address some violations of MISRA C Rule 20.7 Nicola Vetrini
@ 2024-03-18 11:53 ` Nicola Vetrini
  2024-03-18 16:42   ` Jan Beulich
  2024-03-18 11:53 ` [XEN PATCH 02/10] AMD/IOMMU: guest: address violations of MISRA C " Nicola Vetrini
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Nicola Vetrini @ 2024-03-18 11:53 UTC (permalink / raw)
  To: nicola.vetrini, xen-devel
  Cc: sstabellini, michal.orzel, xenia.ragiadakou, ayan.kumar.halder,
	consulting, Jan Beulich, Andrew Cooper, Roger Pau Monné,
	Wei Liu

MISRA C Rule 20.7 states: "Expressions resulting from the expansion
of macro parameters shall be enclosed in parentheses". Therefore, some
macro definitions should gain additional parentheses to ensure that all
current and future users will be safe with respect to expansions that
can possibly alter the semantics of the passed-in macro parameter.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
---
 xen/arch/x86/include/asm/cpufeatureset.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/arch/x86/include/asm/cpufeatureset.h b/xen/arch/x86/include/asm/cpufeatureset.h
index f179229f192f..a9c51bc514a8 100644
--- a/xen/arch/x86/include/asm/cpufeatureset.h
+++ b/xen/arch/x86/include/asm/cpufeatureset.h
@@ -5,7 +5,7 @@
 
 #include <xen/stringify.h>
 
-#define XEN_CPUFEATURE(name, value) X86_FEATURE_##name = value,
+#define XEN_CPUFEATURE(name, value) X86_FEATURE_##name = (value),
 enum {
 #include <public/arch-x86/cpufeatureset.h>
 #include <asm/cpufeatures.h>
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [XEN PATCH 02/10] AMD/IOMMU: guest: address violations of MISRA C Rule 20.7
  2024-03-18 11:53 [XEN PATCH 00/10] address some violations of MISRA C Rule 20.7 Nicola Vetrini
  2024-03-18 11:53 ` [XEN PATCH 01/10] x86/cpufeature: add parentheses to comply with " Nicola Vetrini
@ 2024-03-18 11:53 ` Nicola Vetrini
  2024-03-18 16:43   ` Jan Beulich
  2024-03-18 11:53 ` [XEN PATCH 03/10] xen/xsm: add parentheses to comply with " Nicola Vetrini
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Nicola Vetrini @ 2024-03-18 11:53 UTC (permalink / raw)
  To: nicola.vetrini, xen-devel
  Cc: sstabellini, michal.orzel, xenia.ragiadakou, ayan.kumar.halder,
	consulting, Jan Beulich, Andrew Cooper

MISRA C Rule 20.7 states: "Expressions resulting from the expansion
of macro parameters shall be enclosed in parentheses". Therefore, some
macro definitions should gain additional parentheses to ensure that all
current and future users will be safe with respect to expansions that
can possibly alter the semantics of the passed-in macro parameter.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
---
This local helper may disappear as a follow-up to [1], if the function that
remains there after the cleanup ends up being removed, so this patch has a slight
dependency on what follows up from that thread (in which case it can be dropped).

[1] https://lore.kernel.org/xen-devel/alpine.DEB.2.22.394.2403151724380.853156@ubuntu-linux-20-04-desktop/T/#m9474ad4f35830345a22acd4a665245f7085d4b46
---
 xen/drivers/passthrough/amd/iommu_guest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/drivers/passthrough/amd/iommu_guest.c b/xen/drivers/passthrough/amd/iommu_guest.c
index 4c4252eea116..5bfaa48d9d65 100644
--- a/xen/drivers/passthrough/amd/iommu_guest.c
+++ b/xen/drivers/passthrough/amd/iommu_guest.c
@@ -30,7 +30,7 @@
 #define GUEST_ADDRESS_SIZE_6_LEVEL              0x2
 #define HOST_ADDRESS_SIZE_6_LEVEL               0x2
 
-#define reg_to_u64(reg) (((uint64_t)reg.hi << 32) | reg.lo )
+#define reg_to_u64(reg) (((uint64_t)((reg).hi << 32)) | (reg).lo )
 #define u64_to_reg(reg, val) \
     do \
     { \
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [XEN PATCH 03/10] xen/xsm: add parentheses to comply with MISRA C Rule 20.7
  2024-03-18 11:53 [XEN PATCH 00/10] address some violations of MISRA C Rule 20.7 Nicola Vetrini
  2024-03-18 11:53 ` [XEN PATCH 01/10] x86/cpufeature: add parentheses to comply with " Nicola Vetrini
  2024-03-18 11:53 ` [XEN PATCH 02/10] AMD/IOMMU: guest: address violations of MISRA C " Nicola Vetrini
@ 2024-03-18 11:53 ` Nicola Vetrini
  2024-03-19  3:32   ` Stefano Stabellini
  2024-03-18 11:53 ` [XEN PATCH 04/10] xen/device_tree: address violations of " Nicola Vetrini
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Nicola Vetrini @ 2024-03-18 11:53 UTC (permalink / raw)
  To: nicola.vetrini, xen-devel
  Cc: sstabellini, michal.orzel, xenia.ragiadakou, ayan.kumar.halder,
	consulting, Daniel P. Smith

MISRA C Rule 20.7 states: "Expressions resulting from the expansion
of macro parameters shall be enclosed in parentheses". Therefore, some
macro definitions should gain additional parentheses to ensure that all
current and future users will be safe with respect to expansions that
can possibly alter the semantics of the passed-in macro parameter.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
---
 xen/include/xsm/dummy.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/include/xsm/dummy.h b/xen/include/xsm/dummy.h
index 8671af1ba4d3..88039fdd227c 100644
--- a/xen/include/xsm/dummy.h
+++ b/xen/include/xsm/dummy.h
@@ -58,7 +58,7 @@ void __xsm_action_mismatch_detected(void);
 
 #define XSM_DEFAULT_ARG /* */
 #define XSM_DEFAULT_VOID void
-#define XSM_ASSERT_ACTION(def) xsm_default_t action = def; (void)action
+#define XSM_ASSERT_ACTION(def) xsm_default_t action = (def); (void)action
 
 #else /* CONFIG_XSM */
 
@@ -71,7 +71,7 @@ void __xsm_action_mismatch_detected(void);
 #define XSM_INLINE always_inline
 #define XSM_DEFAULT_ARG xsm_default_t action,
 #define XSM_DEFAULT_VOID xsm_default_t action
-#define XSM_ASSERT_ACTION(def) LINKER_BUG_ON(def != action)
+#define XSM_ASSERT_ACTION(def) LINKER_BUG_ON((def) != action)
 
 #endif /* CONFIG_XSM */
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [XEN PATCH 04/10] xen/device_tree: address violations of MISRA C Rule 20.7
  2024-03-18 11:53 [XEN PATCH 00/10] address some violations of MISRA C Rule 20.7 Nicola Vetrini
                   ` (2 preceding siblings ...)
  2024-03-18 11:53 ` [XEN PATCH 03/10] xen/xsm: add parentheses to comply with " Nicola Vetrini
@ 2024-03-18 11:53 ` Nicola Vetrini
  2024-03-19  3:33   ` Stefano Stabellini
  2024-03-18 11:53 ` [XEN PATCH 05/10] EFI: " Nicola Vetrini
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Nicola Vetrini @ 2024-03-18 11:53 UTC (permalink / raw)
  To: nicola.vetrini, xen-devel
  Cc: sstabellini, michal.orzel, xenia.ragiadakou, ayan.kumar.halder,
	consulting, Julien Grall

MISRA C Rule 20.7 states: "Expressions resulting from the expansion
of macro parameters shall be enclosed in parentheses". Therefore, some
macro definitions should gain additional parentheses to ensure that all
current and future users will be safe with respect to expansions that
can possibly alter the semantics of the passed-in macro parameter.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
---
This patch uniforms the way these macros use parentheses, skipping the
already deviated cases of the lhs of an assignment. In principle, all
three could have the parentheses on the macro argument in the lhs added.
---
 xen/include/xen/device_tree.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h
index 6fe2fa8b2123..e6287305a7b5 100644
--- a/xen/include/xen/device_tree.h
+++ b/xen/include/xen/device_tree.h
@@ -250,7 +250,7 @@ dt_find_interrupt_controller(const struct dt_device_match *matches);
     for ( pp = (dn)->properties; (pp) != NULL; pp = (pp)->next )
 
 #define dt_for_each_device_node(dt, dn)                     \
-    for ( dn = dt; (dn) != NULL; dn = (dn)->allnext )
+    for ( dn = (dt); (dn) != NULL; dn = (dn)->allnext )
 
 #define dt_for_each_child_node(dt, dn)                      \
     for ( dn = (dt)->child; (dn) != NULL; dn = (dn)->sibling )
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [XEN PATCH 05/10] EFI: address violations of MISRA C Rule 20.7
  2024-03-18 11:53 [XEN PATCH 00/10] address some violations of MISRA C Rule 20.7 Nicola Vetrini
                   ` (3 preceding siblings ...)
  2024-03-18 11:53 ` [XEN PATCH 04/10] xen/device_tree: address violations of " Nicola Vetrini
@ 2024-03-18 11:53 ` Nicola Vetrini
  2024-03-18 16:47   ` Jan Beulich
  2024-03-18 11:53 ` [XEN PATCH 06/10] xen/arm: smmu: " Nicola Vetrini
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Nicola Vetrini @ 2024-03-18 11:53 UTC (permalink / raw)
  To: nicola.vetrini, xen-devel
  Cc: sstabellini, michal.orzel, xenia.ragiadakou, ayan.kumar.halder,
	consulting, Jan Beulich

MISRA C Rule 20.7 states: "Expressions resulting from the expansion
of macro parameters shall be enclosed in parentheses". Therefore, some
macro definitions should gain additional parentheses to ensure that all
current and future users will be safe with respect to expansions that
can possibly alter the semantics of the passed-in macro parameter.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
---
This file is matched by exclude-list.json, but the fix is rather trivial
and actually benefits code that is in scope for compliance.
---
 xen/include/efi/efierr.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/include/efi/efierr.h b/xen/include/efi/efierr.h
index dfd3d3cf4867..2ecde0b31302 100644
--- a/xen/include/efi/efierr.h
+++ b/xen/include/efi/efierr.h
@@ -22,7 +22,7 @@ Revision History
 
 
 #define EFIWARN(a)                            (a)
-#define EFI_ERROR(a)              (((INTN) a) < 0)
+#define EFI_ERROR(a)              (((INTN)(a)) < 0)
 
 
 #define EFI_SUCCESS                             0
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [XEN PATCH 06/10] xen/arm: smmu: address violations of MISRA C Rule 20.7
  2024-03-18 11:53 [XEN PATCH 00/10] address some violations of MISRA C Rule 20.7 Nicola Vetrini
                   ` (4 preceding siblings ...)
  2024-03-18 11:53 ` [XEN PATCH 05/10] EFI: " Nicola Vetrini
@ 2024-03-18 11:53 ` Nicola Vetrini
  2024-03-19  3:32   ` Stefano Stabellini
  2024-03-18 11:53 ` [XEN PATCH 07/10] xen/efi: efibind: " Nicola Vetrini
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Nicola Vetrini @ 2024-03-18 11:53 UTC (permalink / raw)
  To: nicola.vetrini, xen-devel
  Cc: sstabellini, michal.orzel, xenia.ragiadakou, ayan.kumar.halder,
	consulting, Julien Grall, Rahul Singh, Bertrand Marquis,
	Volodymyr Babchuk

MISRA C Rule 20.7 states: "Expressions resulting from the expansion
of macro parameters shall be enclosed in parentheses". Therefore, some
macro definitions should gain additional parentheses to ensure that all
current and future users will be safe with respect to expansions that
can possibly alter the semantics of the passed-in macro parameter.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
---
 xen/drivers/passthrough/arm/smmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c
index 83196057a937..f2cee82f553a 100644
--- a/xen/drivers/passthrough/arm/smmu.c
+++ b/xen/drivers/passthrough/arm/smmu.c
@@ -326,7 +326,7 @@ static struct iommu_group *iommu_group_get(struct device *dev)
  */
 #define ARM_SMMU_GR0_NS(smmu)						\
 	((smmu)->base +							\
-		((smmu->options & ARM_SMMU_OPT_SECURE_CFG_ACCESS)	\
+		(((smmu)->options & ARM_SMMU_OPT_SECURE_CFG_ACCESS)	\
 			? 0x400 : 0))
 
 /* Page table bits */
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [XEN PATCH 07/10] xen/efi: efibind: address violations of MISRA C Rule 20.7
  2024-03-18 11:53 [XEN PATCH 00/10] address some violations of MISRA C Rule 20.7 Nicola Vetrini
                   ` (5 preceding siblings ...)
  2024-03-18 11:53 ` [XEN PATCH 06/10] xen/arm: smmu: " Nicola Vetrini
@ 2024-03-18 11:53 ` Nicola Vetrini
  2024-03-18 16:49   ` Jan Beulich
  2024-03-18 11:53 ` [XEN PATCH 08/10] xen/notifier: " Nicola Vetrini
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Nicola Vetrini @ 2024-03-18 11:53 UTC (permalink / raw)
  To: nicola.vetrini, xen-devel
  Cc: sstabellini, michal.orzel, xenia.ragiadakou, ayan.kumar.halder,
	consulting, Julien Grall, Bertrand Marquis, Volodymyr Babchuk,
	Jan Beulich, Andrew Cooper, Roger Pau Monné,
	Wei Liu

MISRA C Rule 20.7 states: "Expressions resulting from the expansion
of macro parameters shall be enclosed in parentheses". Therefore, some
macro definitions should gain additional parentheses to ensure that all
current and future users will be safe with respect to expansions that
can possibly alter the semantics of the passed-in macro parameter.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
---
This file is matched by exclude-list.json, but the fix is rather trivial
and impacts code that in under the scope of MISRA compliance.
---
 xen/arch/arm/include/asm/arm64/efibind.h  | 4 ++--
 xen/arch/x86/include/asm/x86_64/efibind.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/xen/arch/arm/include/asm/arm64/efibind.h b/xen/arch/arm/include/asm/arm64/efibind.h
index f13eadd4f0ab..a1323d452e2e 100644
--- a/xen/arch/arm/include/asm/arm64/efibind.h
+++ b/xen/arch/arm/include/asm/arm64/efibind.h
@@ -22,9 +22,9 @@ Revision History
 #pragma pack()
 #endif
 
-#define EFIERR(a)           (0x8000000000000000ULL | a)
+#define EFIERR(a)           (0x8000000000000000ULL | (a))
 #define EFI_ERROR_MASK      0x8000000000000000ULL
-#define EFIERR_OEM(a)       (0xc000000000000000ULL | a)
+#define EFIERR_OEM(a)       (0xc000000000000000ULL | (a))
 
 #define BAD_POINTER         0xFBFBFBFBFBFBFBFBULL
 #define MAX_ADDRESS         0xFFFFFFFFFFFFFFFFULL
diff --git a/xen/arch/x86/include/asm/x86_64/efibind.h b/xen/arch/x86/include/asm/x86_64/efibind.h
index e23cd16cb6a0..28bc18c24bb3 100644
--- a/xen/arch/x86/include/asm/x86_64/efibind.h
+++ b/xen/arch/x86/include/asm/x86_64/efibind.h
@@ -117,9 +117,9 @@ typedef uint64_t   UINTN;
     #endif
 #endif
 
-#define EFIERR(a)           (0x8000000000000000 | a)
+#define EFIERR(a)           (0x8000000000000000 | (a))
 #define EFI_ERROR_MASK      0x8000000000000000
-#define EFIERR_OEM(a)       (0xc000000000000000 | a)
+#define EFIERR_OEM(a)       (0xc000000000000000 | (a))
 
 
 #define BAD_POINTER         0xFBFBFBFBFBFBFBFB
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [XEN PATCH 08/10] xen/notifier: address violations of MISRA C Rule 20.7
  2024-03-18 11:53 [XEN PATCH 00/10] address some violations of MISRA C Rule 20.7 Nicola Vetrini
                   ` (6 preceding siblings ...)
  2024-03-18 11:53 ` [XEN PATCH 07/10] xen/efi: efibind: " Nicola Vetrini
@ 2024-03-18 11:53 ` Nicola Vetrini
  2024-03-18 16:50   ` Jan Beulich
  2024-03-18 11:53 ` [XEN PATCH 09/10] xen/wait: " Nicola Vetrini
  2024-03-18 11:53 ` [XEN PATCH 10/10] xen/sched: " Nicola Vetrini
  9 siblings, 1 reply; 22+ messages in thread
From: Nicola Vetrini @ 2024-03-18 11:53 UTC (permalink / raw)
  To: nicola.vetrini, xen-devel
  Cc: sstabellini, michal.orzel, xenia.ragiadakou, ayan.kumar.halder,
	consulting, Andrew Cooper, George Dunlap, Jan Beulich,
	Julien Grall, Wei Liu

MISRA C Rule 20.7 states: "Expressions resulting from the expansion
of macro parameters shall be enclosed in parentheses". Therefore, some
macro definitions should gain additional parentheses to ensure that all
current and future users will be safe with respect to expansions that
can possibly alter the semantics of the passed-in macro parameter.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
---
 xen/include/xen/notifier.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/include/xen/notifier.h b/xen/include/xen/notifier.h
index 2a952484df43..05359e8a850d 100644
--- a/xen/include/xen/notifier.h
+++ b/xen/include/xen/notifier.h
@@ -34,7 +34,7 @@ struct notifier_head {
 };
 
 #define NOTIFIER_HEAD(name) \
-    struct notifier_head name = { .head = LIST_HEAD_INIT(name.head) }
+    struct notifier_head name = { .head = LIST_HEAD_INIT((name).head) }
 
 
 void notifier_chain_register(
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [XEN PATCH 09/10] xen/wait: address violations of MISRA C Rule 20.7
  2024-03-18 11:53 [XEN PATCH 00/10] address some violations of MISRA C Rule 20.7 Nicola Vetrini
                   ` (7 preceding siblings ...)
  2024-03-18 11:53 ` [XEN PATCH 08/10] xen/notifier: " Nicola Vetrini
@ 2024-03-18 11:53 ` Nicola Vetrini
  2024-03-18 16:51   ` Jan Beulich
  2024-03-18 11:53 ` [XEN PATCH 10/10] xen/sched: " Nicola Vetrini
  9 siblings, 1 reply; 22+ messages in thread
From: Nicola Vetrini @ 2024-03-18 11:53 UTC (permalink / raw)
  To: nicola.vetrini, xen-devel
  Cc: sstabellini, michal.orzel, xenia.ragiadakou, ayan.kumar.halder,
	consulting, Andrew Cooper, George Dunlap, Jan Beulich,
	Julien Grall, Wei Liu

MISRA C Rule 20.7 states: "Expressions resulting from the expansion
of macro parameters shall be enclosed in parentheses". Therefore, some
macro definitions should gain additional parentheses to ensure that all
current and future users will be safe with respect to expansions that
can possibly alter the semantics of the passed-in macro parameter.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
---
 xen/include/xen/wait.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/include/xen/wait.h b/xen/include/xen/wait.h
index 6eb7667d9c7f..1c68bc564b09 100644
--- a/xen/include/xen/wait.h
+++ b/xen/include/xen/wait.h
@@ -40,12 +40,12 @@ do {                                            \
     if ( condition )                            \
         break;                                  \
     for ( ; ; ) {                               \
-        prepare_to_wait(&wq);                   \
+        prepare_to_wait(&(wq));                 \
         if ( condition )                        \
             break;                              \
         wait();                                 \
     }                                           \
-    finish_wait(&wq);                           \
+    finish_wait(&(wq));                         \
 } while (0)
 
 /* Private functions. */
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [XEN PATCH 10/10] xen/sched: address violations of MISRA C Rule 20.7
  2024-03-18 11:53 [XEN PATCH 00/10] address some violations of MISRA C Rule 20.7 Nicola Vetrini
                   ` (8 preceding siblings ...)
  2024-03-18 11:53 ` [XEN PATCH 09/10] xen/wait: " Nicola Vetrini
@ 2024-03-18 11:53 ` Nicola Vetrini
  2024-03-18 12:00   ` George Dunlap
  9 siblings, 1 reply; 22+ messages in thread
From: Nicola Vetrini @ 2024-03-18 11:53 UTC (permalink / raw)
  To: nicola.vetrini, xen-devel
  Cc: sstabellini, michal.orzel, xenia.ragiadakou, ayan.kumar.halder,
	consulting, George Dunlap, Dario Faggioli

MISRA C Rule 20.7 states: "Expressions resulting from the expansion
of macro parameters shall be enclosed in parentheses". Therefore, some
macro definitions should gain additional parentheses to ensure that all
current and future users will be safe with respect to expansions that
can possibly alter the semantics of the passed-in macro parameter.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
---
 xen/common/sched/private.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/common/sched/private.h b/xen/common/sched/private.h
index 459d1dfb11a5..c0e7c96d24f4 100644
--- a/xen/common/sched/private.h
+++ b/xen/common/sched/private.h
@@ -540,7 +540,7 @@ static inline void sched_unit_unpause(const struct sched_unit *unit)
 }
 
 #define REGISTER_SCHEDULER(x) static const struct scheduler *x##_entry \
-  __used_section(".data.schedulers") = &x
+  __used_section(".data.schedulers") = &(x)
 
 struct cpupool
 {
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [XEN PATCH 10/10] xen/sched: address violations of MISRA C Rule 20.7
  2024-03-18 11:53 ` [XEN PATCH 10/10] xen/sched: " Nicola Vetrini
@ 2024-03-18 12:00   ` George Dunlap
  0 siblings, 0 replies; 22+ messages in thread
From: George Dunlap @ 2024-03-18 12:00 UTC (permalink / raw)
  To: Nicola Vetrini
  Cc: xen-devel, sstabellini, michal.orzel, xenia.ragiadakou,
	ayan.kumar.halder, consulting, Dario Faggioli

On Mon, Mar 18, 2024 at 11:54 AM Nicola Vetrini
<nicola.vetrini@bugseng.com> wrote:
>
> MISRA C Rule 20.7 states: "Expressions resulting from the expansion
> of macro parameters shall be enclosed in parentheses". Therefore, some
> macro definitions should gain additional parentheses to ensure that all
> current and future users will be safe with respect to expansions that
> can possibly alter the semantics of the passed-in macro parameter.
>
> No functional change.
>
> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
> ---
>  xen/common/sched/private.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/xen/common/sched/private.h b/xen/common/sched/private.h
> index 459d1dfb11a5..c0e7c96d24f4 100644
> --- a/xen/common/sched/private.h
> +++ b/xen/common/sched/private.h
> @@ -540,7 +540,7 @@ static inline void sched_unit_unpause(const struct sched_unit *unit)
>  }
>
>  #define REGISTER_SCHEDULER(x) static const struct scheduler *x##_entry \
> -  __used_section(".data.schedulers") = &x
> +  __used_section(".data.schedulers") = &(x)

Arguably this is safe, because any `x` which would be problematic in
this line wouldn't compile in the line above.

But it's almost certainly not worth the effort of documenting or deviating, so:

Acked-by: George Dunlap <george.dunlap@cloud.com>


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [XEN PATCH 01/10] x86/cpufeature: add parentheses to comply with Rule 20.7
  2024-03-18 11:53 ` [XEN PATCH 01/10] x86/cpufeature: add parentheses to comply with " Nicola Vetrini
@ 2024-03-18 16:42   ` Jan Beulich
  0 siblings, 0 replies; 22+ messages in thread
From: Jan Beulich @ 2024-03-18 16:42 UTC (permalink / raw)
  To: Nicola Vetrini
  Cc: sstabellini, michal.orzel, xenia.ragiadakou, ayan.kumar.halder,
	consulting, Andrew Cooper, Roger Pau Monné,
	Wei Liu, xen-devel

On 18.03.2024 12:53, Nicola Vetrini wrote:
> MISRA C Rule 20.7 states: "Expressions resulting from the expansion
> of macro parameters shall be enclosed in parentheses". Therefore, some
> macro definitions should gain additional parentheses to ensure that all
> current and future users will be safe with respect to expansions that
> can possibly alter the semantics of the passed-in macro parameter.
> 
> No functional change.
> 
> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>

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




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [XEN PATCH 02/10] AMD/IOMMU: guest: address violations of MISRA C Rule 20.7
  2024-03-18 11:53 ` [XEN PATCH 02/10] AMD/IOMMU: guest: address violations of MISRA C " Nicola Vetrini
@ 2024-03-18 16:43   ` Jan Beulich
  0 siblings, 0 replies; 22+ messages in thread
From: Jan Beulich @ 2024-03-18 16:43 UTC (permalink / raw)
  To: Nicola Vetrini
  Cc: sstabellini, michal.orzel, xenia.ragiadakou, ayan.kumar.halder,
	consulting, Andrew Cooper, xen-devel

On 18.03.2024 12:53, Nicola Vetrini wrote:
> MISRA C Rule 20.7 states: "Expressions resulting from the expansion
> of macro parameters shall be enclosed in parentheses". Therefore, some
> macro definitions should gain additional parentheses to ensure that all
> current and future users will be safe with respect to expansions that
> can possibly alter the semantics of the passed-in macro parameter.
> 
> No functional change.
> 
> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
> ---
> This local helper may disappear as a follow-up to [1], if the function that
> remains there after the cleanup ends up being removed, so this patch has a slight
> dependency on what follows up from that thread (in which case it can be dropped).

Indeed let's not add more churn to the file before it disappears.

Jan

> [1] https://lore.kernel.org/xen-devel/alpine.DEB.2.22.394.2403151724380.853156@ubuntu-linux-20-04-desktop/T/#m9474ad4f35830345a22acd4a665245f7085d4b46



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [XEN PATCH 05/10] EFI: address violations of MISRA C Rule 20.7
  2024-03-18 11:53 ` [XEN PATCH 05/10] EFI: " Nicola Vetrini
@ 2024-03-18 16:47   ` Jan Beulich
  0 siblings, 0 replies; 22+ messages in thread
From: Jan Beulich @ 2024-03-18 16:47 UTC (permalink / raw)
  To: Nicola Vetrini
  Cc: sstabellini, michal.orzel, xenia.ragiadakou, ayan.kumar.halder,
	consulting, xen-devel

On 18.03.2024 12:53, Nicola Vetrini wrote:
> MISRA C Rule 20.7 states: "Expressions resulting from the expansion
> of macro parameters shall be enclosed in parentheses". Therefore, some
> macro definitions should gain additional parentheses to ensure that all
> current and future users will be safe with respect to expansions that
> can possibly alter the semantics of the passed-in macro parameter.
> 
> No functional change.
> 
> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
> ---
> This file is matched by exclude-list.json, but the fix is rather trivial
> and actually benefits code that is in scope for compliance.

Hmm, yes, the change is simple enough to not be a big hindrance even if we
were to pull in incremental updates from gnu-efi, so
Acked-by: Jan Beulich <jbeulich@suse.com>

Albeit preferably with ...

> --- a/xen/include/efi/efierr.h
> +++ b/xen/include/efi/efierr.h
> @@ -22,7 +22,7 @@ Revision History
>  
>  
>  #define EFIWARN(a)                            (a)
> -#define EFI_ERROR(a)              (((INTN) a) < 0)
> +#define EFI_ERROR(a)              (((INTN)(a)) < 0)

... excess parentheses dropped in exchange:

#define EFI_ERROR(a)              ((INTN)(a) < 0)

I may take the liberty of doing so while committing.

Jan


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [XEN PATCH 07/10] xen/efi: efibind: address violations of MISRA C Rule 20.7
  2024-03-18 11:53 ` [XEN PATCH 07/10] xen/efi: efibind: " Nicola Vetrini
@ 2024-03-18 16:49   ` Jan Beulich
  2024-03-18 17:03     ` Nicola Vetrini
  0 siblings, 1 reply; 22+ messages in thread
From: Jan Beulich @ 2024-03-18 16:49 UTC (permalink / raw)
  To: Nicola Vetrini
  Cc: sstabellini, michal.orzel, xenia.ragiadakou, ayan.kumar.halder,
	consulting, Julien Grall, Bertrand Marquis, Volodymyr Babchuk,
	Andrew Cooper, Roger Pau Monné,
	Wei Liu, xen-devel

On 18.03.2024 12:53, Nicola Vetrini wrote:
> MISRA C Rule 20.7 states: "Expressions resulting from the expansion
> of macro parameters shall be enclosed in parentheses". Therefore, some
> macro definitions should gain additional parentheses to ensure that all
> current and future users will be safe with respect to expansions that
> can possibly alter the semantics of the passed-in macro parameter.
> 
> No functional change.
> 
> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
> ---
> This file is matched by exclude-list.json, but the fix is rather trivial
> and impacts code that in under the scope of MISRA compliance.

On the same basis as the other change:
Acked-by: Jan Beulich <jbeulich@suse.com>

I wonder though: Where do we draw the line?

Jan


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [XEN PATCH 08/10] xen/notifier: address violations of MISRA C Rule 20.7
  2024-03-18 11:53 ` [XEN PATCH 08/10] xen/notifier: " Nicola Vetrini
@ 2024-03-18 16:50   ` Jan Beulich
  0 siblings, 0 replies; 22+ messages in thread
From: Jan Beulich @ 2024-03-18 16:50 UTC (permalink / raw)
  To: Nicola Vetrini
  Cc: sstabellini, michal.orzel, xenia.ragiadakou, ayan.kumar.halder,
	consulting, Andrew Cooper, George Dunlap, Julien Grall, Wei Liu,
	xen-devel

On 18.03.2024 12:53, Nicola Vetrini wrote:
> MISRA C Rule 20.7 states: "Expressions resulting from the expansion
> of macro parameters shall be enclosed in parentheses". Therefore, some
> macro definitions should gain additional parentheses to ensure that all
> current and future users will be safe with respect to expansions that
> can possibly alter the semantics of the passed-in macro parameter.
> 
> No functional change.
> 
> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>

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




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [XEN PATCH 09/10] xen/wait: address violations of MISRA C Rule 20.7
  2024-03-18 11:53 ` [XEN PATCH 09/10] xen/wait: " Nicola Vetrini
@ 2024-03-18 16:51   ` Jan Beulich
  0 siblings, 0 replies; 22+ messages in thread
From: Jan Beulich @ 2024-03-18 16:51 UTC (permalink / raw)
  To: Nicola Vetrini
  Cc: sstabellini, michal.orzel, xenia.ragiadakou, ayan.kumar.halder,
	consulting, Andrew Cooper, George Dunlap, Julien Grall, Wei Liu,
	xen-devel

On 18.03.2024 12:53, Nicola Vetrini wrote:
> MISRA C Rule 20.7 states: "Expressions resulting from the expansion
> of macro parameters shall be enclosed in parentheses". Therefore, some
> macro definitions should gain additional parentheses to ensure that all
> current and future users will be safe with respect to expansions that
> can possibly alter the semantics of the passed-in macro parameter.
> 
> No functional change.
> 
> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>

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




^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [XEN PATCH 07/10] xen/efi: efibind: address violations of MISRA C Rule 20.7
  2024-03-18 16:49   ` Jan Beulich
@ 2024-03-18 17:03     ` Nicola Vetrini
  0 siblings, 0 replies; 22+ messages in thread
From: Nicola Vetrini @ 2024-03-18 17:03 UTC (permalink / raw)
  To: Jan Beulich
  Cc: sstabellini, michal.orzel, xenia.ragiadakou, ayan.kumar.halder,
	consulting, Julien Grall, Bertrand Marquis, Volodymyr Babchuk,
	Andrew Cooper, Roger Pau Monné,
	Wei Liu, xen-devel

On 2024-03-18 17:49, Jan Beulich wrote:
> On 18.03.2024 12:53, Nicola Vetrini wrote:
>> MISRA C Rule 20.7 states: "Expressions resulting from the expansion
>> of macro parameters shall be enclosed in parentheses". Therefore, some
>> macro definitions should gain additional parentheses to ensure that 
>> all
>> current and future users will be safe with respect to expansions that
>> can possibly alter the semantics of the passed-in macro parameter.
>> 
>> No functional change.
>> 
>> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
>> ---
>> This file is matched by exclude-list.json, but the fix is rather 
>> trivial
>> and impacts code that in under the scope of MISRA compliance.
> 
> On the same basis as the other change:
> Acked-by: Jan Beulich <jbeulich@suse.com>
> 

Thanks.

> I wonder though: Where do we draw the line?
> 
> Jan

So far the policy, at least from my side, has been to submit a patch if 
the change is simple enough, to avoid adding a special case that needs 
to be documented and maintained.
In case concerns were raised, propose a deviation and follow up from 
there.

-- 
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [XEN PATCH 03/10] xen/xsm: add parentheses to comply with MISRA C Rule 20.7
  2024-03-18 11:53 ` [XEN PATCH 03/10] xen/xsm: add parentheses to comply with " Nicola Vetrini
@ 2024-03-19  3:32   ` Stefano Stabellini
  0 siblings, 0 replies; 22+ messages in thread
From: Stefano Stabellini @ 2024-03-19  3:32 UTC (permalink / raw)
  To: Nicola Vetrini
  Cc: xen-devel, sstabellini, michal.orzel, xenia.ragiadakou,
	ayan.kumar.halder, consulting, Daniel P. Smith

On Mon, 18 Mar 2024, Nicola Vetrini wrote:
> MISRA C Rule 20.7 states: "Expressions resulting from the expansion
> of macro parameters shall be enclosed in parentheses". Therefore, some
> macro definitions should gain additional parentheses to ensure that all
> current and future users will be safe with respect to expansions that
> can possibly alter the semantics of the passed-in macro parameter.
> 
> No functional change.
> 
> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
 
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [XEN PATCH 06/10] xen/arm: smmu: address violations of MISRA C Rule 20.7
  2024-03-18 11:53 ` [XEN PATCH 06/10] xen/arm: smmu: " Nicola Vetrini
@ 2024-03-19  3:32   ` Stefano Stabellini
  0 siblings, 0 replies; 22+ messages in thread
From: Stefano Stabellini @ 2024-03-19  3:32 UTC (permalink / raw)
  To: Nicola Vetrini
  Cc: xen-devel, sstabellini, michal.orzel, xenia.ragiadakou,
	ayan.kumar.halder, consulting, Julien Grall, Rahul Singh,
	Bertrand Marquis, Volodymyr Babchuk

On Mon, 18 Mar 2024, Nicola Vetrini wrote:
> MISRA C Rule 20.7 states: "Expressions resulting from the expansion
> of macro parameters shall be enclosed in parentheses". Therefore, some
> macro definitions should gain additional parentheses to ensure that all
> current and future users will be safe with respect to expansions that
> can possibly alter the semantics of the passed-in macro parameter.
> 
> No functional change.
> 
> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
 


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [XEN PATCH 04/10] xen/device_tree: address violations of MISRA C Rule 20.7
  2024-03-18 11:53 ` [XEN PATCH 04/10] xen/device_tree: address violations of " Nicola Vetrini
@ 2024-03-19  3:33   ` Stefano Stabellini
  0 siblings, 0 replies; 22+ messages in thread
From: Stefano Stabellini @ 2024-03-19  3:33 UTC (permalink / raw)
  To: Nicola Vetrini
  Cc: xen-devel, sstabellini, michal.orzel, xenia.ragiadakou,
	ayan.kumar.halder, consulting, Julien Grall

On Mon, 18 Mar 2024, Nicola Vetrini wrote:
> MISRA C Rule 20.7 states: "Expressions resulting from the expansion
> of macro parameters shall be enclosed in parentheses". Therefore, some
> macro definitions should gain additional parentheses to ensure that all
> current and future users will be safe with respect to expansions that
> can possibly alter the semantics of the passed-in macro parameter.
> 
> No functional change.
> 
> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
 

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2024-03-19  3:33 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-18 11:53 [XEN PATCH 00/10] address some violations of MISRA C Rule 20.7 Nicola Vetrini
2024-03-18 11:53 ` [XEN PATCH 01/10] x86/cpufeature: add parentheses to comply with " Nicola Vetrini
2024-03-18 16:42   ` Jan Beulich
2024-03-18 11:53 ` [XEN PATCH 02/10] AMD/IOMMU: guest: address violations of MISRA C " Nicola Vetrini
2024-03-18 16:43   ` Jan Beulich
2024-03-18 11:53 ` [XEN PATCH 03/10] xen/xsm: add parentheses to comply with " Nicola Vetrini
2024-03-19  3:32   ` Stefano Stabellini
2024-03-18 11:53 ` [XEN PATCH 04/10] xen/device_tree: address violations of " Nicola Vetrini
2024-03-19  3:33   ` Stefano Stabellini
2024-03-18 11:53 ` [XEN PATCH 05/10] EFI: " Nicola Vetrini
2024-03-18 16:47   ` Jan Beulich
2024-03-18 11:53 ` [XEN PATCH 06/10] xen/arm: smmu: " Nicola Vetrini
2024-03-19  3:32   ` Stefano Stabellini
2024-03-18 11:53 ` [XEN PATCH 07/10] xen/efi: efibind: " Nicola Vetrini
2024-03-18 16:49   ` Jan Beulich
2024-03-18 17:03     ` Nicola Vetrini
2024-03-18 11:53 ` [XEN PATCH 08/10] xen/notifier: " Nicola Vetrini
2024-03-18 16:50   ` Jan Beulich
2024-03-18 11:53 ` [XEN PATCH 09/10] xen/wait: " Nicola Vetrini
2024-03-18 16:51   ` Jan Beulich
2024-03-18 11:53 ` [XEN PATCH 10/10] xen/sched: " Nicola Vetrini
2024-03-18 12:00   ` George Dunlap

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.