Skip to contentSkip to conversation

xen/cpu: Minor coding style fixes

PATCH In review Xenia Ragiadakou 3 participants 8 messages Aug 5, 2022

lore
Share & tools
lore
#0 lore raw

v2 cover xen/cpu: Minor coding style fixes

Xenia Ragiadakou (3):
xen/cpu: Fix MISRA C 2012 Rule 20.7 violation xen/cpu: Add missing white space around arithmetic operators xen/cpu: Undefine MASK_DECLARE_ macros after their usage

 xen/common/cpu.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/3 xen/cpu: Fix MISRA C 2012 Rule 20.7 violation

In MASK_DECLARE_ macros, the macro parameter 'x' is used as expression and therefore it is good to be enclosed in parentheses to prevent against unintended expansions.

---

Changes in v2:
- fix MISRA C 2012 Rule 20.7 violation in all MASK_DECLARE_ macros

 xen/common/cpu.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
xen/common/cpu.c +4 -4
index b0b63cdb36..feb2a6634e 100644
@@ -25,10 +25,10 @@ const cpumask_t cpumask_all = {
  */
 
 /* cpu_bit_bitmap[0] is empty - so we can back into it */
-#define MASK_DECLARE_1(x) [x+1][0] = 1UL << (x)
-#define MASK_DECLARE_2(x) MASK_DECLARE_1(x), MASK_DECLARE_1(x+1)
-#define MASK_DECLARE_4(x) MASK_DECLARE_2(x), MASK_DECLARE_2(x+2)
-#define MASK_DECLARE_8(x) MASK_DECLARE_4(x), MASK_DECLARE_4(x+4)
+#define MASK_DECLARE_1(x) [(x)+1][0] = 1UL << (x)
+#define MASK_DECLARE_2(x) MASK_DECLARE_1(x), MASK_DECLARE_1((x)+1)
+#define MASK_DECLARE_4(x) MASK_DECLARE_2(x), MASK_DECLARE_2((x)+2)
+#define MASK_DECLARE_8(x) MASK_DECLARE_4(x), MASK_DECLARE_4((x)+4)
 
 const unsigned long cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)] = {
 
Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 2/3 xen/cpu: Add missing white space around arithmetic operators

In reply to Xenia Ragiadakou

---

Changes in v2:
- new patch

 xen/common/cpu.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
xen/common/cpu.c +5 -5
index feb2a6634e..c48a1cabd2 100644
@@ -25,12 +25,12 @@ const cpumask_t cpumask_all = {
  */
 
 /* cpu_bit_bitmap[0] is empty - so we can back into it */
-#define MASK_DECLARE_1(x) [(x)+1][0] = 1UL << (x)
-#define MASK_DECLARE_2(x) MASK_DECLARE_1(x), MASK_DECLARE_1((x)+1)
-#define MASK_DECLARE_4(x) MASK_DECLARE_2(x), MASK_DECLARE_2((x)+2)
-#define MASK_DECLARE_8(x) MASK_DECLARE_4(x), MASK_DECLARE_4((x)+4)
+#define MASK_DECLARE_1(x) [(x) + 1][0] = 1UL << (x)
+#define MASK_DECLARE_2(x) MASK_DECLARE_1(x), MASK_DECLARE_1((x) + 1)
+#define MASK_DECLARE_4(x) MASK_DECLARE_2(x), MASK_DECLARE_2((x) + 2)
+#define MASK_DECLARE_8(x) MASK_DECLARE_4(x), MASK_DECLARE_4((x) + 4)
 
-const unsigned long cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)] = {
+const unsigned long cpu_bit_bitmap[BITS_PER_LONG + 1][BITS_TO_LONGS(NR_CPUS)] = {
 
     MASK_DECLARE_8(0),  MASK_DECLARE_8(8),
     MASK_DECLARE_8(16), MASK_DECLARE_8(24),
Signature · 1 line
2.34.1
#3 lore raw

PATCH v2 3/3 xen/cpu: Undefine MASK_DECLARE_ macros after their usage

In reply to Xenia Ragiadakou

MASK_DECLARE_ macros have only a limited scope. Remove their definitions immediately after their usage.

---

Changes in v2:
- new patch

 xen/common/cpu.c | 5 +++++
 1 file changed, 5 insertions(+)
xen/common/cpu.c +5 -0
index c48a1cabd2..4a048caa49 100644
@@ -40,6 +40,11 @@ const unsigned long cpu_bit_bitmap[BITS_PER_LONG + 1][BITS_TO_LONGS(NR_CPUS)] =
 #endif
 };
 
+#undef MASK_DECLARE_8
+#undef MASK_DECLARE_4
+#undef MASK_DECLARE_2
+#undef MASK_DECLARE_1
+
 static DEFINE_RWLOCK(cpu_add_remove_lock);
 
 bool get_cpu_maps(void)
Signature · 1 line
2.34.1
Acked-by on the v2 series
#4 lore raw
In reply to Xenia Ragiadakou
Quoted 8 lines · Xenia Ragiadakou

Xenia Ragiadakou (3):
xen/cpu: Fix MISRA C 2012 Rule 20.7 violation xen/cpu: Add missing white space around arithmetic operators xen/cpu: Undefine MASK_DECLARE_ macros after their usage

 xen/common/cpu.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

However,
- I don't see why patches 1 and 2 needed splitting, when patch 1 already touches all those lines. It is the usual thing for us to make cosmetic adjustments when touching a line anyway.
- Patch 3, while fine to be separate, wants a Requested-by: or
Suggested-by: me (which I guess can be taken care of while committing).

Jan

#5 lore raw

Hi Jan,

Quoted 10 lines · Jan Beulich
Quoted 8 lines · Xenia Ragiadakou

Xenia Ragiadakou (3):
xen/cpu: Fix MISRA C 2012 Rule 20.7 violation xen/cpu: Add missing white space around arithmetic operators xen/cpu: Undefine MASK_DECLARE_ macros after their usage

  xen/common/cpu.c | 15 ++++++++++-----
  1 file changed, 10 insertions(+), 5 deletions(-)
Quoted 6 lines

However,
- I don't see why patches 1 and 2 needed splitting, when patch 1 already touches all those lines. It is the usual thing for us to make cosmetic adjustments when touching a line anyway.

In my opinion, the initial patch that added the code should not have been accepted in first place without the white spaces around '+'. But maybe coding style rules came later.
Nevertheless, I continue to consider it unfair to rely on and request from new unrelated patches to fix those issues.

Quoted 4 lines

- Patch 3, while fine to be separate, wants a Requested-by: or
Suggested-by: me (which I guess can be taken care of while committing).

Jan

Signature · 1 line
Xenia
#6 lore raw
Quoted 13 lines · Xenia Ragiadakou
Quoted 12 lines · Jan Beulich
Quoted 8 lines · Xenia Ragiadakou

Xenia Ragiadakou (3):
xen/cpu: Fix MISRA C 2012 Rule 20.7 violation xen/cpu: Add missing white space around arithmetic operators xen/cpu: Undefine MASK_DECLARE_ macros after their usage

  xen/common/cpu.c | 15 ++++++++++-----
  1 file changed, 10 insertions(+), 5 deletions(-)
Quoted 8 lines
Quoted 4 lines

However,
- I don't see why patches 1 and 2 needed splitting, when patch 1 already touches all those lines. It is the usual thing for us to make cosmetic adjustments when touching a line anyway.

In my opinion, the initial patch that added the code should not have been accepted in first place without the white spaces around '+'. But maybe coding style rules came later.

Iirc the goal was to take it unaltered from Linux.

Quoted 2 lines

Nevertheless, I continue to consider it unfair to rely on and request from new unrelated patches to fix those issues.

I can certainly see where you're coming from, but please also try to take maintainer perspective: By doing trivial and obvious adjustments at the same time when touching code anyway, there's one less patch to look at (and later to apply). And please also consider how "git blame" or alike
works: By touching the same line(s) twice in close succession, finding the "real" change is made needlessly harder. (Putting the cosmetic change first is generally disliked because it makes backporting harder, in case such is wanted / needed.)

I'm sorry if you take such requests as unfair - they aren't meant to be. They're merely meant to make things as easy as possible for everyone (which may only be on average, yes).

Jan

Reviewed-by on the v2 series
#7 lore raw
In reply to Xenia Ragiadakou

Hi Xenia,

Quoted 10 lines · Xenia Ragiadakou

Xenia Ragiadakou (3):
xen/cpu: Fix MISRA C 2012 Rule 20.7 violation xen/cpu: Add missing white space around arithmetic operators xen/cpu: Undefine MASK_DECLARE_ macros after their usage

xen/common/cpu.c | 15 ++++++++++-----

1 file changed, 10 insertions(+), 5 deletions(-)

But I agree with Jan that some patches could have been squashed but I do not think we need to have a v3 here.

Cheers
Bertrand

Quoted 4 lines
Signature · 1 line
2.34.1