Skip to contentSkip to conversation

address some violations of MISRA C Rule 20.7

PATCH Superseded Nicola Vetrini 3 participants 17 messages Mar 8, 2024 – Mar 11, 2024

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#1 lore raw

PATCH v2 1/7 xen/spinlock: address violations of MISRA C Rule 20.7

In reply to Nicola Vetrini

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.

---
 xen/include/xen/spinlock.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/include/xen/spinlock.h +1 -1
index 1cd9120eac7a..0e6a083dfb9e 100644
@@ -94,7 +94,7 @@ struct lock_profile_qhead {
     int32_t                   idx;     /* index for printout */
 };
 
-#define _LOCK_PROFILE(lockname) { .name = #lockname, .lock = &lockname, }
+#define _LOCK_PROFILE(lockname) { .name = #lockname, .lock = &(lockname), }
 #define _LOCK_PROFILE_PTR(name)                                               \
     static struct lock_profile * const __lock_profile_##name                  \
     __used_section(".lockprofile.data") =                                     \
Signature · 1 line
2.34.1
#3 lore raw

PATCH v2 2/7 xen/include: address violations of MISRA C Rule 20.7

In reply to Nicola Vetrini

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.

---
Changes in v2:
- split from an earlier patch

---
 xen/include/xen/bug.h  | 2 +-
 xen/include/xen/init.h | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
xen/include/xen/bug.h +1 -1
index 2c45c462fc63..77fe1e1ba840 100644
@@ -80,7 +80,7 @@ struct bug_frame {
     [bf_type]    "i" (type),                                                 \
     [bf_ptr]     "i" (ptr),                                                  \
     [bf_msg]     "i" (msg),                                                  \
-    [bf_line_lo] "i" ((line & ((1 << BUG_LINE_LO_WIDTH) - 1))                \
+    [bf_line_lo] "i" (((line) & ((1 << BUG_LINE_LO_WIDTH) - 1))              \
                       << BUG_DISP_WIDTH),                                    \
     [bf_line_hi] "i" (((line) >> BUG_LINE_LO_WIDTH) << BUG_DISP_WIDTH)
 
xen/include/xen/init.h +2 -2
index 1d7c0216bc80..0a4223833755 100644
@@ -63,9 +63,9 @@ typedef int (*initcall_t)(void);
 typedef void (*exitcall_t)(void);
 
 #define presmp_initcall(fn) \
-    const static initcall_t __initcall_##fn __init_call("presmp") = fn
+    const static initcall_t __initcall_##fn __init_call("presmp") = (fn)
 #define __initcall(fn) \
-    const static initcall_t __initcall_##fn __init_call("1") = fn
+    const static initcall_t __initcall_##fn __init_call("1") = (fn)
 #define __exitcall(fn) \
     static exitcall_t __exitcall_##fn __exit_call = fn
 
Signature · 1 line
2.34.1
#5 lore raw

PATCH v2 3/7 xen/list: address violations of MISRA C Rule 20.7

In reply to Nicola Vetrini

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.

---
Changes in v2:
- changes to list.h are all in this patch;
- Parenthesized some instances of "pos" and "n" even when already covered by the deviation on the lhs of an assingment for consistency.

---
 xen/include/xen/list.h | 83 +++++++++++++++++++++---------------------
 1 file changed, 41 insertions(+), 42 deletions(-)
xen/include/xen/list.h +41 -42
index b5eab3a1eb6c..27cafcce2c82 100644
@@ -479,9 +479,9 @@ static inline void list_splice_init(struct list_head *list,
  * @n:      another &struct list_head to use as temporary storage
  * @head:   the head for your list.
  */
-#define list_for_each_backwards_safe(pos, n, head)              \
-    for ( pos = (head)->prev, n = pos->prev; pos != (head);     \
-          pos = n, n = pos->prev )
+#define list_for_each_backwards_safe(pos, n, head)                 \
+    for ( (pos) = (head)->prev, n = (pos)->prev; (pos) != (head);  \
+          (pos) = n, n = (pos)->prev )
 
 /**
  * list_for_each_entry - iterate over list of given type
@@ -490,9 +490,9 @@ static inline void list_splice_init(struct list_head *list,
  * @member: the name of the list_struct within the struct.
  */
 #define list_for_each_entry(pos, head, member)                          \
-    for (pos = list_entry((head)->next, typeof(*pos), member);          \
-         &pos->member != (head);                                        \
-         pos = list_entry(pos->member.next, typeof(*pos), member))
+    for ((pos) = list_entry((head)->next, typeof(*(pos)), member);      \
+         &(pos)->member != (head);                                      \
+         (pos) = list_entry((pos)->member.next, typeof(*(pos)), member))
 
 /**
  * list_for_each_entry_reverse - iterate backwards over list of given type.
@@ -501,9 +501,9 @@ static inline void list_splice_init(struct list_head *list,
  * @member: the name of the list_struct within the struct.
  */
 #define list_for_each_entry_reverse(pos, head, member)                  \
-    for (pos = list_entry((head)->prev, typeof(*pos), member);          \
-         &pos->member != (head);                                        \
-         pos = list_entry(pos->member.prev, typeof(*pos), member))
+    for ((pos) = list_entry((head)->prev, typeof(*(pos)), member);      \
+         &(pos)->member != (head);                                      \
+         (pos) = list_entry((pos)->member.prev, typeof(*(pos)), member))
 
 /**
  * list_prepare_entry - prepare a pos entry for use in
@@ -516,7 +516,7 @@ static inline void list_splice_init(struct list_head *list,
  * list_for_each_entry_continue.
  */
 #define list_prepare_entry(pos, head, member)           \
-    ((pos) ? : list_entry(head, typeof(*pos), member))
+    ((pos) ? : list_entry(head, typeof(*(pos)), member))
 
 /**
  * list_for_each_entry_continue - continue iteration over list of given type
@@ -527,10 +527,10 @@ static inline void list_splice_init(struct list_head *list,
  * Continue to iterate over list of given type, continuing after
  * the current position.
  */
-#define list_for_each_entry_continue(pos, head, member)                 \
-    for (pos = list_entry(pos->member.next, typeof(*pos), member);      \
-         &pos->member != (head);                                        \
-         pos = list_entry(pos->member.next, typeof(*pos), member))
+#define list_for_each_entry_continue(pos, head, member)                   \
+    for ((pos) = list_entry((pos)->member.next, typeof(*(pos)), member);  \
+         &(pos)->member != (head);                                        \
+         (pos) = list_entry((pos)->member.next, typeof(*(pos)), member))
 
 /**
  * list_for_each_entry_from - iterate over list of given type from the
@@ -542,8 +542,8 @@ static inline void list_splice_init(struct list_head *list,
  * Iterate over list of given type, continuing from current position.
  */
 #define list_for_each_entry_from(pos, head, member)                     \
-    for (; &pos->member != (head);                                      \
-         pos = list_entry(pos->member.next, typeof(*pos), member))
+    for (; &(pos)->member != (head);                                    \
+         (pos) = list_entry((pos)->member.next, typeof(*(pos)), member))
 
 /**
  * list_for_each_entry_safe - iterate over list of given type safe
@@ -554,10 +554,10 @@ static inline void list_splice_init(struct list_head *list,
  * @member: the name of the list_struct within the struct.
  */
 #define list_for_each_entry_safe(pos, n, head, member)                  \
-    for (pos = list_entry((head)->next, typeof(*pos), member),          \
-         n = list_entry(pos->member.next, typeof(*pos), member);        \
-         &pos->member != (head);                                        \
-         pos = n, n = list_entry(n->member.next, typeof(*n), member))
+    for ((pos) = list_entry((head)->next, typeof(*(pos)), member),      \
+         (n) = list_entry((pos)->member.next, typeof(*(pos)), member);  \
+         &(pos)->member != (head);                                      \
+         (pos) = (n), (n) = list_entry((n)->member.next, typeof(*(n)), member))
 
 /**
  * list_for_each_entry_safe_continue
@@ -569,11 +569,11 @@ static inline void list_splice_init(struct list_head *list,
  * Iterate over list of given type, continuing after current point,
  * safe against removal of list entry.
  */
-#define list_for_each_entry_safe_continue(pos, n, head, member)         \
-    for (pos = list_entry(pos->member.next, typeof(*pos), member),      \
-         n = list_entry(pos->member.next, typeof(*pos), member);        \
-         &pos->member != (head);                                        \
-         pos = n, n = list_entry(n->member.next, typeof(*n), member))
+#define list_for_each_entry_safe_continue(pos, n, head, member)           \
+    for ((pos) = list_entry((pos)->member.next, typeof(*(pos)), member),  \
+         (n) = list_entry((pos)->member.next, typeof(*(pos)), member);    \
+         &(pos)->member != (head);                                        \
+         (pos) = (n), (n) = list_entry((n)->member.next, typeof(*(n)), member))
 
 /**
  * list_for_each_entry_safe_from
@@ -586,9 +586,9 @@ static inline void list_splice_init(struct list_head *list,
  * removal of list entry.
  */
 #define list_for_each_entry_safe_from(pos, n, head, member)             \
-    for (n = list_entry(pos->member.next, typeof(*pos), member);        \
-         &pos->member != (head);                                        \
-         pos = n, n = list_entry(n->member.next, typeof(*n), member))
+    for ((n) = list_entry((pos)->member.next, typeof(*(pos)), member);  \
+         &(pos)->member != (head);                                      \
+         (pos) = (n), (n) = list_entry((n)->member.next, typeof(*(n)), member))
 
 /**
  * list_for_each_entry_safe_reverse
@@ -601,10 +601,10 @@ static inline void list_splice_init(struct list_head *list,
  * of list entry.
  */
 #define list_for_each_entry_safe_reverse(pos, n, head, member)          \
-    for (pos = list_entry((head)->prev, typeof(*pos), member),          \
-         n = list_entry(pos->member.prev, typeof(*pos), member);        \
-         &pos->member != (head);                                        \
-         pos = n, n = list_entry(n->member.prev, typeof(*n), member))
+    for ((pos) = list_entry((head)->prev, typeof(*(pos)), member),      \
+         (n) = list_entry((pos)->member.prev, typeof(*(pos)), member);  \
+         &(pos)->member != (head);                                      \
+         (pos) = (n), (n) = list_entry((n)->member.prev, typeof(*(n)), member))
 
 /**
  * list_for_each_rcu - iterate over an rcu-protected list
@@ -616,14 +616,14 @@ static inline void list_splice_init(struct list_head *list,
  * as long as the traversal is guarded by rcu_read_lock().
  */
 #define list_for_each_rcu(pos, head)                            \
-    for (pos = (head)->next;                                    \
+    for ((pos) = (head)->next;                                  \
          rcu_dereference(pos) != (head);                        \
-         pos = pos->next)
+         (pos) = (pos)->next)
 
 #define __list_for_each_rcu(pos, head)          \
-    for (pos = (head)->next;                    \
+    for ((pos) = (head)->next;                  \
          rcu_dereference(pos) != (head);        \
-         pos = pos->next)
+         (pos) = (pos)->next)
 
 /**
  * list_for_each_safe_rcu
@@ -638,9 +638,9 @@ static inline void list_splice_init(struct list_head *list,
  * as long as the traversal is guarded by rcu_read_lock().
  */
 #define list_for_each_safe_rcu(pos, n, head)            \
-    for (pos = (head)->next;                            \
-         n = rcu_dereference(pos)->next, pos != (head); \
-         pos = n)
+    for ((pos) = (head)->next;                          \
+         (n) = rcu_dereference(pos)->next, (pos) != (head); \
+         (pos) = (n))
 
 /**
  * list_for_each_entry_rcu - iterate over rcu list of given type
@@ -653,9 +653,9 @@ static inline void list_splice_init(struct list_head *list,
  * as long as the traversal is guarded by rcu_read_lock().
  */
 #define list_for_each_entry_rcu(pos, head, member)                      \
-    for (pos = list_entry((head)->next, typeof(*pos), member);          \
+    for ((pos) = list_entry((head)->next, typeof(*(pos)), member);      \
          &rcu_dereference(pos)->member != (head);                       \
-         pos = list_entry(pos->member.next, typeof(*pos), member))
+         (pos) = list_entry((pos)->member.next, typeof(*(pos)), member))
 
 /**
  * list_for_each_continue_rcu
@@ -977,4 +977,3 @@ static inline void hlist_add_after_rcu(struct hlist_node *prev,
           pos = pos->next)
 
 #endif /* __XEN_LIST_H__ */
-
Signature · 1 line
2.34.1
#9 lore raw

PATCH v2 4/7 xen/param: address violations of MISRA C Rule 20.7

In reply to Nicola Vetrini

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.

---
 xen/include/xen/param.h | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
xen/include/xen/param.h +11 -11
index 13607e0e50e0..1bdbab34ab1f 100644
@@ -45,42 +45,42 @@ extern const struct kernel_param __setup_start[], __setup_end[];
 #define TEMP_NAME(base) _TEMP_NAME(base, __LINE__)
 
 #define custom_param(_name, _var) \
-    __setup_str __setup_str_##_var[] = _name; \
+    __setup_str __setup_str_##_var[] = (_name); \
     __kparam __setup_##_var = \
         { .name = __setup_str_##_var, \
           .type = OPT_CUSTOM, \
-          .par.func = _var }
+          .par.func = (_var) }
 #define boolean_param(_name, _var) \
-    __setup_str __setup_str_##_var[] = _name; \
+    __setup_str __setup_str_##_var[] = (_name); \
     __kparam __setup_##_var = \
         { .name = __setup_str_##_var, \
           .type = OPT_BOOL, \
           .len = sizeof(_var) + \
                  BUILD_BUG_ON_ZERO(sizeof(_var) != sizeof(bool)), \
-          .par.var = &_var }
+          .par.var = &(_var) }
 #define integer_param(_name, _var) \
-    __setup_str __setup_str_##_var[] = _name; \
+    __setup_str __setup_str_##_var[] = (_name); \
     __kparam __setup_##_var = \
         { .name = __setup_str_##_var, \
           .type = OPT_UINT, \
           .len = sizeof(_var), \
-          .par.var = &_var }
+          .par.var = &(_var) }
 #define size_param(_name, _var) \
-    __setup_str __setup_str_##_var[] = _name; \
+    __setup_str __setup_str_##_var[] = (_name); \
     __kparam __setup_##_var = \
         { .name = __setup_str_##_var, \
           .type = OPT_SIZE, \
           .len = sizeof(_var), \
-          .par.var = &_var }
+          .par.var = &(_var) }
 #define string_param(_name, _var) \
-    __setup_str __setup_str_##_var[] = _name; \
+    __setup_str __setup_str_##_var[] = (_name); \
     __kparam __setup_##_var = \
         { .name = __setup_str_##_var, \
           .type = OPT_STR, \
           .len = sizeof(_var), \
-          .par.var = &_var }
+          .par.var = &(_var) }
 #define ignore_param(_name)                 \
-    __setup_str TEMP_NAME(__setup_str_ign)[] = _name;    \
+    __setup_str TEMP_NAME(__setup_str_ign)[] = (_name);  \
     __kparam TEMP_NAME(__setup_ign) =                    \
         { .name = TEMP_NAME(__setup_str_ign),            \
           .type = OPT_IGNORE }
Signature · 1 line
2.34.1
#0 lore raw

v2 cover address some violations of MISRA C Rule 20.7

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), but in some cases (most notably in patch 3) such adjustments have been made for consistency.

This series fixes a significant portion of the violations on Arm (from ~14000 to ~2500). On x86, though there is one patch touching it, there are still many more; they will be part of a later series.

Changes in v2:
- Removed a hunk of patch 1 touching __config_enabled (will be deviated in a subsequent series).
- Split patch 1 into three patches, for easier reviewing.
- Made minor adjustments to "xen-arm-address-some...".
- Dropped GUARD(1) hunk from the x86 patch.
- Dropped patch 4, 5 and 10: they will be subject to a deviation in the future.
- Patch 7, 8, 9 have been committed already.

Nicola Vetrini (7):
xen/spinlock: address violations of MISRA C Rule 20.7 xen/include: address violations of MISRA C Rule 20.7 xen/list: address violations of MISRA C Rule 20.7 xen/param: address violations of MISRA C Rule 20.7 xen/arm: address some violations of MISRA C Rule 20.7 x86/irq: parenthesize negative constants arm/smmu: address some violations of MISRA C Rule 20.7

 xen/arch/arm/arm64/cpufeature.c          | 14 ++--
 xen/arch/arm/cpuerrata.c                 |  8 +--
 xen/arch/arm/include/asm/arm64/sysregs.h |  2 +-
 xen/arch/arm/include/asm/guest_atomics.h |  4 +-
 xen/arch/arm/include/asm/mm.h            |  2 +-
 xen/arch/arm/include/asm/smccc.h         | 36 +++++-----
 xen/arch/arm/include/asm/vgic-emul.h     |  8 +--
 xen/arch/arm/vcpreg.c                    |  5 +-
 xen/arch/x86/include/asm/irq.h           |  8 +--
 xen/drivers/passthrough/arm/smmu.c       |  4 +-
 xen/include/xen/bug.h                    |  2 +-
 xen/include/xen/init.h                   |  4 +-
 xen/include/xen/list.h                   | 83 ++++++++++++------------
 xen/include/xen/param.h                  | 22 +++----
 xen/include/xen/spinlock.h               |  2 +-
 15 files changed, 102 insertions(+), 102 deletions(-)
Signature · 1 line
2.34.1
#13 lore raw

PATCH v2 6/7 x86/irq: parenthesize negative constants

These constants are parenthesized to avoid them from possibly influencing the semantics of the constructs where it is used, especially inside macros invocations.

This also resolves some violations of MISRA C Rule 20.7 ("Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses").

No functional change.

---
Changes in v2:
- dropped the controversial GUARD(1) hunk

---
 xen/arch/x86/include/asm/irq.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
xen/arch/x86/include/asm/irq.h +4 -4
index 082a3d6bbc6a..7d49f3c1904a 100644
@@ -172,16 +172,16 @@ void cleanup_domain_irq_mapping(struct domain *d);
     void *__ret = radix_tree_lookup(&(d)->arch.irq_pirq, irq);  \
     __ret ? radix_tree_ptr_to_int(__ret) : 0;                   \
 })
-#define PIRQ_ALLOCATED -1
+#define PIRQ_ALLOCATED (-1)
 #define domain_pirq_to_emuirq(d, pirq) pirq_field(d, pirq,              \
     arch.hvm.emuirq, IRQ_UNBOUND)
 #define domain_emuirq_to_pirq(d, emuirq) ({                             \
     void *__ret = radix_tree_lookup(&(d)->arch.hvm.emuirq_pirq, emuirq);\
     __ret ? radix_tree_ptr_to_int(__ret) : IRQ_UNBOUND;                 \
 })
-#define IRQ_UNBOUND -1
-#define IRQ_PT -2
-#define IRQ_MSI_EMU -3
+#define IRQ_UNBOUND (-1)
+#define IRQ_PT      (-2)
+#define IRQ_MSI_EMU (-3)
 
 bool cpu_has_pending_apic_eoi(void);
 
Signature · 1 line
2.34.1
#11 lore raw

PATCH v2 5/7 xen/arm: address some violations of MISRA C Rule 20.7

In reply to Nicola Vetrini

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.

---
Style in arm64/cpufeature.c has not been amended, because this file seems to be kept in sync with its Linux counterpart.

Changes in v2:
- Added parentheses for consistency

---
 xen/arch/arm/arm64/cpufeature.c          | 14 ++++-----
 xen/arch/arm/cpuerrata.c                 |  8 +++---
 xen/arch/arm/include/asm/arm64/sysregs.h |  2 +-
 xen/arch/arm/include/asm/guest_atomics.h |  4 +--
 xen/arch/arm/include/asm/mm.h            |  2 +-
 xen/arch/arm/include/asm/smccc.h         | 36 ++++++++++++------------
 xen/arch/arm/include/asm/vgic-emul.h     |  8 +++---
 xen/arch/arm/vcpreg.c                    |  5 ++--
 8 files changed, 40 insertions(+), 39 deletions(-)
xen/arch/arm/arm64/cpufeature.c +7 -7
index 864413d9cc03..6fb8974ade7f 100644
@@ -78,13 +78,13 @@
 
 #define __ARM64_FTR_BITS(SIGNED, VISIBLE, STRICT, TYPE, SHIFT, WIDTH, SAFE_VAL) \
 	{						\
-		.sign = SIGNED,				\
-		.visible = VISIBLE,			\
-		.strict = STRICT,			\
-		.type = TYPE,				\
-		.shift = SHIFT,				\
-		.width = WIDTH,				\
-		.safe_val = SAFE_VAL,			\
+		.sign = (SIGNED),				\
+		.visible = (VISIBLE),			\
+		.strict = (STRICT),			\
+		.type = (TYPE),				\
+		.shift = (SHIFT),				\
+		.width = (WIDTH),				\
+		.safe_val = (SAFE_VAL),			\
 	}
 
 /* Define a feature with unsigned values */
xen/arch/arm/cpuerrata.c +4 -4
index a28fa6ac78cc..2b7101ea2524 100644
@@ -461,13 +461,13 @@ static bool has_ssbd_mitigation(const struct arm_cpu_capabilities *entry)
 
 #define MIDR_RANGE(model, min, max)     \
     .matches = is_affected_midr_range,  \
-    .midr_model = model,                \
-    .midr_range_min = min,              \
-    .midr_range_max = max
+    .midr_model = (model),              \
+    .midr_range_min = (min),            \
+    .midr_range_max = (max)
 
 #define MIDR_ALL_VERSIONS(model)        \
     .matches = is_affected_midr_range,  \
-    .midr_model = model,                \
+    .midr_model = (model),              \
     .midr_range_min = 0,                \
     .midr_range_max = (MIDR_VARIANT_MASK | MIDR_REVISION_MASK)
 
xen/arch/arm/include/asm/arm64/sysregs.h +1 -1
index 3fdeb9d8cdef..b593e4028b53 100644
@@ -465,7 +465,7 @@
 /* Access to system registers */
 
 #define WRITE_SYSREG64(v, name) do {                    \
-    uint64_t _r = v;                                    \
+    uint64_t _r = (v);                                  \
     asm volatile("msr "__stringify(name)", %0" : : "r" (_r));       \
 } while (0)
 #define READ_SYSREG64(name) ({                          \
xen/arch/arm/include/asm/guest_atomics.h +2 -2
index a1745f8613f6..8893eb9a55d7 100644
@@ -32,7 +32,7 @@ static inline void guest_##name(struct domain *d, int nr, volatile void *p) \
     perfc_incr(atomics_guest_paused);                                       \
                                                                             \
     domain_pause_nosync(d);                                                 \
-    name(nr, p);                                                            \
+    (name)(nr, p);                                                          \
     domain_unpause(d);                                                      \
 }
 
@@ -52,7 +52,7 @@ static inline int guest_##name(struct domain *d, int nr, volatile void *p)  \
     perfc_incr(atomics_guest_paused);                                       \
                                                                             \
     domain_pause_nosync(d);                                                 \
-    oldbit = name(nr, p);                                                   \
+    oldbit = (name)(nr, p);                                                 \
     domain_unpause(d);                                                      \
                                                                             \
     return oldbit;                                                          \
xen/arch/arm/include/asm/mm.h +1 -1
index cbcf3bf14767..48538b5337aa 100644
@@ -250,7 +250,7 @@ static inline void __iomem *ioremap_wc(paddr_t start, size_t len)
 #define gaddr_to_gfn(ga)    _gfn(paddr_to_pfn(ga))
 #define mfn_to_maddr(mfn)   pfn_to_paddr(mfn_x(mfn))
 #define maddr_to_mfn(ma)    _mfn(paddr_to_pfn(ma))
-#define vmap_to_mfn(va)     maddr_to_mfn(virt_to_maddr((vaddr_t)va))
+#define vmap_to_mfn(va)     maddr_to_mfn(virt_to_maddr((vaddr_t)(va)))
 #define vmap_to_page(va)    mfn_to_page(vmap_to_mfn(va))
 
 /* Page-align address and convert to frame number format */
xen/arch/arm/include/asm/smccc.h +18 -18
index 1adcd37443c7..a289c48b7ffd 100644
@@ -122,56 +122,56 @@ struct arm_smccc_res {
 #define __constraint_read_7 __constraint_read_6, "r" (r7)
 
 #define __declare_arg_0(a0, res)                            \
-    struct arm_smccc_res    *___res = res;                  \
-    register unsigned long  r0 ASM_REG(0) = (uint32_t)a0;   \
+    struct arm_smccc_res    *___res = (res);                \
+    register unsigned long  r0 ASM_REG(0) = (uint32_t)(a0); \
     register unsigned long  r1 ASM_REG(1);                  \
     register unsigned long  r2 ASM_REG(2);                  \
     register unsigned long  r3 ASM_REG(3)
 
 #define __declare_arg_1(a0, a1, res)                        \
-    typeof(a1) __a1 = a1;                                   \
-    struct arm_smccc_res    *___res = res;                  \
-    register unsigned long  r0 ASM_REG(0) = (uint32_t)a0;   \
+    typeof(a1) __a1 = (a1);                                 \
+    struct arm_smccc_res    *___res = (res);                \
+    register unsigned long  r0 ASM_REG(0) = (uint32_t)(a0); \
     register unsigned long  r1 ASM_REG(1) = __a1;           \
     register unsigned long  r2 ASM_REG(2);                  \
     register unsigned long  r3 ASM_REG(3)
 
 #define __declare_arg_2(a0, a1, a2, res)                    \
-    typeof(a1) __a1 = a1;                                   \
-    typeof(a2) __a2 = a2;                                   \
-    struct arm_smccc_res    *___res = res;				    \
-    register unsigned long  r0 ASM_REG(0) = (uint32_t)a0;   \
+    typeof(a1) __a1 = (a1);                                 \
+    typeof(a2) __a2 = (a2);                                 \
+    struct arm_smccc_res    *___res = (res);                \
+    register unsigned long  r0 ASM_REG(0) = (uint32_t)(a0); \
     register unsigned long  r1 ASM_REG(1) = __a1;           \
     register unsigned long  r2 ASM_REG(2) = __a2;           \
     register unsigned long  r3 ASM_REG(3)
 
 #define __declare_arg_3(a0, a1, a2, a3, res)                \
-    typeof(a1) __a1 = a1;                                   \
-    typeof(a2) __a2 = a2;                                   \
-    typeof(a3) __a3 = a3;                                   \
-    struct arm_smccc_res    *___res = res;                  \
-    register unsigned long  r0 ASM_REG(0) = (uint32_t)a0;   \
+    typeof(a1) __a1 = (a1);                                 \
+    typeof(a2) __a2 = (a2);                                 \
+    typeof(a3) __a3 = (a3);                                 \
+    struct arm_smccc_res    *___res = (res);                \
+    register unsigned long  r0 ASM_REG(0) = (uint32_t)(a0); \
     register unsigned long  r1 ASM_REG(1) = __a1;           \
     register unsigned long  r2 ASM_REG(2) = __a2;           \
     register unsigned long  r3 ASM_REG(3) = __a3
 
 #define __declare_arg_4(a0, a1, a2, a3, a4, res)        \
-    typeof(a4) __a4 = a4;                               \
+    typeof(a4) __a4 = (a4);                             \
     __declare_arg_3(a0, a1, a2, a3, res);               \
     register unsigned long r4 ASM_REG(4) = __a4
 
 #define __declare_arg_5(a0, a1, a2, a3, a4, a5, res)    \
-    typeof(a5) __a5 = a5;                               \
+    typeof(a5) __a5 = (a5);                             \
     __declare_arg_4(a0, a1, a2, a3, a4, res);           \
     register typeof(a5) r5 ASM_REG(5) = __a5
 
 #define __declare_arg_6(a0, a1, a2, a3, a4, a5, a6, res)    \
-    typeof(a6) __a6 = a6;                                   \
+    typeof(a6) __a6 = (a6);                                 \
     __declare_arg_5(a0, a1, a2, a3, a4, a5, res);           \
     register typeof(a6) r6 ASM_REG(6) = __a6
 
 #define __declare_arg_7(a0, a1, a2, a3, a4, a5, a6, a7, res)    \
-    typeof(a7) __a7 = a7;                                       \
+    typeof(a7) __a7 = (a7);                                     \
     __declare_arg_6(a0, a1, a2, a3, a4, a5, a6, res);           \
     register typeof(a7) r7 ASM_REG(7) = __a7
 
xen/arch/arm/include/asm/vgic-emul.h +4 -4
index e52fbaa3ec04..fd0cfa2175fe 100644
@@ -6,11 +6,11 @@
  * a range of registers
  */
 
-#define VREG32(reg) reg ... reg + 3
-#define VREG64(reg) reg ... reg + 7
+#define VREG32(reg) (reg) ... ((reg) + 3)
+#define VREG64(reg) (reg) ... ((reg) + 7)
 
-#define VRANGE32(start, end) start ... end + 3
-#define VRANGE64(start, end) start ... end + 7
+#define VRANGE32(start, end) (start) ... ((end) + 3)
+#define VRANGE64(start, end) (start) ... ((end) + 7)
 
 /*
  * 64 bits registers can be accessible using 32-bit and 64-bit unless
xen/arch/arm/vcpreg.c +3 -2
index a2d050070473..019cf34f003a 100644
@@ -39,7 +39,8 @@
  */
 
 #ifdef CONFIG_ARM_64
-#define WRITE_SYSREG_SZ(sz, val, sysreg) WRITE_SYSREG((uint##sz##_t)val, sysreg)
+#define WRITE_SYSREG_SZ(sz, val, sysreg) \
+    WRITE_SYSREG((uint##sz##_t)(val), sysreg)
 #else
 /*
  * WRITE_SYSREG{32/64} on arm32 is defined as variadic macro which imposes
@@ -64,7 +65,7 @@ static bool func(struct cpu_user_regs *regs, type##sz##_t *r, bool read)    \
     bool cache_enabled = vcpu_has_cache_enabled(v);                         \
                                                                             \
     GUEST_BUG_ON(read);                                                     \
-    WRITE_SYSREG_SZ(sz, *r, reg);                                           \
+    WRITE_SYSREG_SZ(sz, *(r), reg);                                         \
                                                                             \
     p2m_toggle_cache(v, cache_enabled);                                     \
                                                                             \
Signature · 1 line
2.34.1
#16 lore raw

PATCH v2 7/7 arm/smmu: address some violations of MISRA C Rule 20.7

In reply to Nicola Vetrini

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.

---
 xen/drivers/passthrough/arm/smmu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/drivers/passthrough/arm/smmu.c +2 -2
index 625ed0e41961..83196057a937 100644
@@ -242,7 +242,7 @@ struct arm_smmu_xen_device {
 	struct iommu_group *group;
 };
 
-#define dev_archdata(dev) ((struct arm_smmu_xen_device *)dev->iommu)
+#define dev_archdata(dev) ((struct arm_smmu_xen_device *)(dev)->iommu)
 #define dev_iommu_domain(dev) (dev_archdata(dev)->domain)
 #define dev_iommu_group(dev) (dev_archdata(dev)->group)
 
@@ -627,7 +627,7 @@ struct arm_smmu_master_cfg {
 };
 #define INVALID_SMENDX			-1
 #define for_each_cfg_sme(cfg, i, idx, num) \
-	for (i = 0; idx = cfg->smendx[i], i < num; ++i)
+	for (i = 0; idx = (cfg)->smendx[i], (i) < (num); ++(i))
 
 struct arm_smmu_master {
 	struct device_node		*of_node;
Signature · 1 line
2.34.1
Reviewed-by on v2 1/7
#2 lore raw

Re: [XEN PATCH v2 1/7] xen/spinlock: address violations of MISRA C Rule 20.7

In reply to Nicola Vetrini
Quoted 9 lines · Nicola Vetrini

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.

Reviewed-by on v2 2/7
#4 lore raw

Re: [XEN PATCH v2 2/7] xen/include: address violations of MISRA C Rule 20.7

In reply to Nicola Vetrini
Quoted 9 lines · Nicola Vetrini

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.

Reviewed-by on v2 3/7
#6 lore raw

Re: [XEN PATCH v2 3/7] xen/list: address violations of MISRA C Rule 20.7

In reply to Nicola Vetrini
Quoted 9 lines · Nicola Vetrini

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.

Reviewed-by on v2 4/7
#10 lore raw

Re: [XEN PATCH v2 4/7] xen/param: address violations of MISRA C Rule 20.7

In reply to Nicola Vetrini
Quoted 9 lines · Nicola Vetrini

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.

Reviewed-by on v2 5/7
#12 lore raw

Re: [XEN PATCH v2 5/7] xen/arm: address some violations of MISRA C Rule 20.7

In reply to Nicola Vetrini
Quoted 9 lines · Nicola Vetrini

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.

There are a couple of cases below where parentheses are not strictly necessary but this patch is following the decided deviation pattern.

Quoted 237 lines

---
Style in arm64/cpufeature.c has not been amended, because this file seems to be kept in sync with its Linux counterpart.

Changes in v2:
- Added parentheses for consistency

---
 xen/arch/arm/arm64/cpufeature.c          | 14 ++++-----
 xen/arch/arm/cpuerrata.c                 |  8 +++---
 xen/arch/arm/include/asm/arm64/sysregs.h |  2 +-
 xen/arch/arm/include/asm/guest_atomics.h |  4 +--
 xen/arch/arm/include/asm/mm.h            |  2 +-
 xen/arch/arm/include/asm/smccc.h         | 36 ++++++++++++------------
 xen/arch/arm/include/asm/vgic-emul.h     |  8 +++---
 xen/arch/arm/vcpreg.c                    |  5 ++--
 8 files changed, 40 insertions(+), 39 deletions(-)
xen/arch/arm/arm64/cpufeature.c +7 -7
index 864413d9cc03..6fb8974ade7f 100644
@@ -78,13 +78,13 @@
 
 #define __ARM64_FTR_BITS(SIGNED, VISIBLE, STRICT, TYPE, SHIFT, WIDTH, SAFE_VAL) \
 	{						\
-		.sign = SIGNED,				\
-		.visible = VISIBLE,			\
-		.strict = STRICT,			\
-		.type = TYPE,				\
-		.shift = SHIFT,				\
-		.width = WIDTH,				\
-		.safe_val = SAFE_VAL,			\
+		.sign = (SIGNED),				\
+		.visible = (VISIBLE),			\
+		.strict = (STRICT),			\
+		.type = (TYPE),				\
+		.shift = (SHIFT),				\
+		.width = (WIDTH),				\
+		.safe_val = (SAFE_VAL),			\
 	}
 
 /* Define a feature with unsigned values */
xen/arch/arm/cpuerrata.c +4 -4
index a28fa6ac78cc..2b7101ea2524 100644
@@ -461,13 +461,13 @@ static bool has_ssbd_mitigation(const struct arm_cpu_capabilities *entry)
 
 #define MIDR_RANGE(model, min, max)     \
     .matches = is_affected_midr_range,  \
-    .midr_model = model,                \
-    .midr_range_min = min,              \
-    .midr_range_max = max
+    .midr_model = (model),              \
+    .midr_range_min = (min),            \
+    .midr_range_max = (max)
 
 #define MIDR_ALL_VERSIONS(model)        \
     .matches = is_affected_midr_range,  \
-    .midr_model = model,                \
+    .midr_model = (model),              \
     .midr_range_min = 0,                \
     .midr_range_max = (MIDR_VARIANT_MASK | MIDR_REVISION_MASK)
 
xen/arch/arm/include/asm/arm64/sysregs.h +1 -1
index 3fdeb9d8cdef..b593e4028b53 100644
@@ -465,7 +465,7 @@
 /* Access to system registers */
 
 #define WRITE_SYSREG64(v, name) do {                    \
-    uint64_t _r = v;                                    \
+    uint64_t _r = (v);                                  \
     asm volatile("msr "__stringify(name)", %0" : : "r" (_r));       \
 } while (0)
 #define READ_SYSREG64(name) ({                          \
xen/arch/arm/include/asm/guest_atomics.h +2 -2
index a1745f8613f6..8893eb9a55d7 100644
@@ -32,7 +32,7 @@ static inline void guest_##name(struct domain *d, int nr, volatile void *p) \
     perfc_incr(atomics_guest_paused);                                       \
                                                                             \
     domain_pause_nosync(d);                                                 \
-    name(nr, p);                                                            \
+    (name)(nr, p);                                                          \
     domain_unpause(d);                                                      \
 }
 
@@ -52,7 +52,7 @@ static inline int guest_##name(struct domain *d, int nr, volatile void *p)  \
     perfc_incr(atomics_guest_paused);                                       \
                                                                             \
     domain_pause_nosync(d);                                                 \
-    oldbit = name(nr, p);                                                   \
+    oldbit = (name)(nr, p);                                                 \
     domain_unpause(d);                                                      \
                                                                             \
     return oldbit;                                                          \
xen/arch/arm/include/asm/mm.h +1 -1
index cbcf3bf14767..48538b5337aa 100644
@@ -250,7 +250,7 @@ static inline void __iomem *ioremap_wc(paddr_t start, size_t len)
 #define gaddr_to_gfn(ga)    _gfn(paddr_to_pfn(ga))
 #define mfn_to_maddr(mfn)   pfn_to_paddr(mfn_x(mfn))
 #define maddr_to_mfn(ma)    _mfn(paddr_to_pfn(ma))
-#define vmap_to_mfn(va)     maddr_to_mfn(virt_to_maddr((vaddr_t)va))
+#define vmap_to_mfn(va)     maddr_to_mfn(virt_to_maddr((vaddr_t)(va)))
 #define vmap_to_page(va)    mfn_to_page(vmap_to_mfn(va))
 
 /* Page-align address and convert to frame number format */
xen/arch/arm/include/asm/smccc.h +18 -18
index 1adcd37443c7..a289c48b7ffd 100644
@@ -122,56 +122,56 @@ struct arm_smccc_res {
 #define __constraint_read_7 __constraint_read_6, "r" (r7)
 
 #define __declare_arg_0(a0, res)                            \
-    struct arm_smccc_res    *___res = res;                  \
-    register unsigned long  r0 ASM_REG(0) = (uint32_t)a0;   \
+    struct arm_smccc_res    *___res = (res);                \
+    register unsigned long  r0 ASM_REG(0) = (uint32_t)(a0); \
     register unsigned long  r1 ASM_REG(1);                  \
     register unsigned long  r2 ASM_REG(2);                  \
     register unsigned long  r3 ASM_REG(3)
 
 #define __declare_arg_1(a0, a1, res)                        \
-    typeof(a1) __a1 = a1;                                   \
-    struct arm_smccc_res    *___res = res;                  \
-    register unsigned long  r0 ASM_REG(0) = (uint32_t)a0;   \
+    typeof(a1) __a1 = (a1);                                 \
+    struct arm_smccc_res    *___res = (res);                \
+    register unsigned long  r0 ASM_REG(0) = (uint32_t)(a0); \
     register unsigned long  r1 ASM_REG(1) = __a1;           \
     register unsigned long  r2 ASM_REG(2);                  \
     register unsigned long  r3 ASM_REG(3)
 
 #define __declare_arg_2(a0, a1, a2, res)                    \
-    typeof(a1) __a1 = a1;                                   \
-    typeof(a2) __a2 = a2;                                   \
-    struct arm_smccc_res    *___res = res;				    \
-    register unsigned long  r0 ASM_REG(0) = (uint32_t)a0;   \
+    typeof(a1) __a1 = (a1);                                 \
+    typeof(a2) __a2 = (a2);                                 \
+    struct arm_smccc_res    *___res = (res);                \
+    register unsigned long  r0 ASM_REG(0) = (uint32_t)(a0); \
     register unsigned long  r1 ASM_REG(1) = __a1;           \
     register unsigned long  r2 ASM_REG(2) = __a2;           \
     register unsigned long  r3 ASM_REG(3)
 
 #define __declare_arg_3(a0, a1, a2, a3, res)                \
-    typeof(a1) __a1 = a1;                                   \
-    typeof(a2) __a2 = a2;                                   \
-    typeof(a3) __a3 = a3;                                   \
-    struct arm_smccc_res    *___res = res;                  \
-    register unsigned long  r0 ASM_REG(0) = (uint32_t)a0;   \
+    typeof(a1) __a1 = (a1);                                 \
+    typeof(a2) __a2 = (a2);                                 \
+    typeof(a3) __a3 = (a3);                                 \
+    struct arm_smccc_res    *___res = (res);                \
+    register unsigned long  r0 ASM_REG(0) = (uint32_t)(a0); \
     register unsigned long  r1 ASM_REG(1) = __a1;           \
     register unsigned long  r2 ASM_REG(2) = __a2;           \
     register unsigned long  r3 ASM_REG(3) = __a3
 
 #define __declare_arg_4(a0, a1, a2, a3, a4, res)        \
-    typeof(a4) __a4 = a4;                               \
+    typeof(a4) __a4 = (a4);                             \
     __declare_arg_3(a0, a1, a2, a3, res);               \
     register unsigned long r4 ASM_REG(4) = __a4
 
 #define __declare_arg_5(a0, a1, a2, a3, a4, a5, res)    \
-    typeof(a5) __a5 = a5;                               \
+    typeof(a5) __a5 = (a5);                             \
     __declare_arg_4(a0, a1, a2, a3, a4, res);           \
     register typeof(a5) r5 ASM_REG(5) = __a5
 
 #define __declare_arg_6(a0, a1, a2, a3, a4, a5, a6, res)    \
-    typeof(a6) __a6 = a6;                                   \
+    typeof(a6) __a6 = (a6);                                 \
     __declare_arg_5(a0, a1, a2, a3, a4, a5, res);           \
     register typeof(a6) r6 ASM_REG(6) = __a6
 
 #define __declare_arg_7(a0, a1, a2, a3, a4, a5, a6, a7, res)    \
-    typeof(a7) __a7 = a7;                                       \
+    typeof(a7) __a7 = (a7);                                     \
     __declare_arg_6(a0, a1, a2, a3, a4, a5, a6, res);           \
     register typeof(a7) r7 ASM_REG(7) = __a7
 
xen/arch/arm/include/asm/vgic-emul.h +4 -4
index e52fbaa3ec04..fd0cfa2175fe 100644
@@ -6,11 +6,11 @@
  * a range of registers
  */
 
-#define VREG32(reg) reg ... reg + 3
-#define VREG64(reg) reg ... reg + 7
+#define VREG32(reg) (reg) ... ((reg) + 3)
+#define VREG64(reg) (reg) ... ((reg) + 7)
 
-#define VRANGE32(start, end) start ... end + 3
-#define VRANGE64(start, end) start ... end + 7
+#define VRANGE32(start, end) (start) ... ((end) + 3)
+#define VRANGE64(start, end) (start) ... ((end) + 7)
 
 /*
  * 64 bits registers can be accessible using 32-bit and 64-bit unless
xen/arch/arm/vcpreg.c +3 -2
index a2d050070473..019cf34f003a 100644
@@ -39,7 +39,8 @@
  */
 
 #ifdef CONFIG_ARM_64
-#define WRITE_SYSREG_SZ(sz, val, sysreg) WRITE_SYSREG((uint##sz##_t)val, sysreg)
+#define WRITE_SYSREG_SZ(sz, val, sysreg) \
+    WRITE_SYSREG((uint##sz##_t)(val), sysreg)
 #else
 /*
  * WRITE_SYSREG{32/64} on arm32 is defined as variadic macro which imposes
@@ -64,7 +65,7 @@ static bool func(struct cpu_user_regs *regs, type##sz##_t *r, bool read)    \
     bool cache_enabled = vcpu_has_cache_enabled(v);                         \
                                                                             \
     GUEST_BUG_ON(read);                                                     \
-    WRITE_SYSREG_SZ(sz, *r, reg);                                           \
+    WRITE_SYSREG_SZ(sz, *(r), reg);                                         \
                                                                             \
     p2m_toggle_cache(v, cache_enabled);                                     \
                                                                             \
Signature · 1 line
2.34.1
Reviewed-by on v2 6/7
#14 lore raw

Re: [XEN PATCH v2 6/7] x86/irq: parenthesize negative constants

In reply to Nicola Vetrini
Quoted 11 lines · Nicola Vetrini

These constants are parenthesized to avoid them from possibly influencing the semantics of the constructs where it is used, especially inside macros invocations.

This also resolves some violations of MISRA C Rule 20.7 ("Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses").

No functional change.

#7 lore raw

Re: [XEN PATCH v2 3/7] xen/list: address violations of MISRA C Rule 20.7

In reply to Nicola Vetrini

xen/include/xen/list.h static inline void list_splice_init(struct list_head *list, · line 484

Quoted 12 lines · Nicola Vetrini
xen/include/xen/list.h +3 -3
@@ -479,9 +479,9 @@ static inline void list_splice_init(struct list_head *list,
  * @n:      another &struct list_head to use as temporary storage
  * @head:   the head for your list.
  */
-#define list_for_each_backwards_safe(pos, n, head)              \
-    for ( pos = (head)->prev, n = pos->prev; pos != (head);     \
-          pos = n, n = pos->prev )
+#define list_for_each_backwards_safe(pos, n, head)                 \
+    for ( (pos) = (head)->prev, n = (pos)->prev; (pos) != (head);  \
+          (pos) = n, n = (pos)->prev )

I think this is worse than before and incomplete: At least the rhs use of n also needs parenthesizing. Plus if pos is parenthesized even in lhs instances, imo n ought to be, too.

Jan

Acked-by
#15 lore raw

Re: [XEN PATCH v2 6/7] x86/irq: parenthesize negative constants

In reply to Stefano Stabellini
Quoted 9 lines · Stefano Stabellini
Quoted 8 lines · Nicola Vetrini

These constants are parenthesized to avoid them from possibly influencing the semantics of the constructs where it is used, especially inside macros invocations.

This also resolves some violations of MISRA C Rule 20.7 ("Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses").

Quoted 5 lines
Quoted 3 lines

No functional change.

#8 lore raw

Re: [XEN PATCH v2 3/7] xen/list: address violations of MISRA C Rule 20.7

In reply to Jan Beulich
Quoted 10 lines · Jan Beulich
Quoted 9 lines · Nicola Vetrini
xen/include/xen/list.h +0 -2
@@ -479,9 +479,9 @@ static inline void list_splice_init(struct 
 list_head *list,
  * @n:      another &struct list_head to use as temporary storage
  * @head:   the head for your list.
  */
-#define list_for_each_backwards_safe(pos, n, head)              \
-    for ( pos = (head)->prev, n = pos->prev; pos != (head);     \
Quoted 9 lines

xen/include/xen/list.h static inline void list_splice_init(struct list_head *list, · line 484

Quoted 4 lines
xen/include/xen/list.h +3 -1
-          pos = n, n = pos->prev )
+#define list_for_each_backwards_safe(pos, n, head)                 \
+    for ( (pos) = (head)->prev, n = (pos)->prev; (pos) != (head);  \
+          (pos) = n, n = (pos)->prev )

I think this is worse than before and incomplete: At least the rhs use of n also needs parenthesizing. Plus if pos is parenthesized even in lhs instances, imo n ought to be, too.

You are right: this was simply an oversight.

Signature · 2 lines
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)