Skip to contentSkip to conversation

powerpc/mm/radix: add missing braces for single statement block

PATCH In review Mathieu Malaterre 3 participants 7 messages Apr 8, 2018 – May 25, 2018 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/mm/radix: add missing braces for single statement block

In commit 7a22d6321c3d ("powerpc/mm/radix: Update command line parsing for disable_radix") an if statement was added for a possible empty body (prom_debug).

Fix the following warning, treated as error with W=1:

arch/powerpc/kernel/prom_init.c:656:46: error: suggest braces around empty body in an ‘if’ statement [-Werror=empty-body]

---
 arch/powerpc/kernel/prom_init.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/kernel/prom_init.c +2 -1
index 5ae153b97d0a..f0e802495530 100644
@@ -652,8 +652,9 @@ static void __init early_cmdline_parse(void)
 		} else
 			prom_radix_disable = true;
 	}
-	if (prom_radix_disable)
+	if (prom_radix_disable) {
 		prom_debug("Radix disabled from cmdline\n");
+	}
 }
 
 #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
Signature · 1 line
2.11.0
#1 lore raw
Quoted 18 lines · Mathieu Malaterre

In commit 7a22d6321c3d ("powerpc/mm/radix: Update command line parsing for disable_radix") an if statement was added for a possible empty body (prom_debug).

Fix the following warning, treated as error with W=1:

arch/powerpc/kernel/prom_init.c:656:46: error: suggest braces around empty body in an ‘if’ statement [-Werror=empty-body]

---
 arch/powerpc/kernel/prom_init.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/kernel/prom_init.c +0 -0
index 5ae153b97d0a..f0e802495530 100644

arch/powerpc/kernel/prom_init.c static void __init early_cmdline_parse(void) · line 656

Quoted 6 lines
arch/powerpc/kernel/prom_init.c +1 -1
@@ -652,8 +652,9 @@ static void __init early_cmdline_parse(void)
 		} else
 			prom_radix_disable = true;
 	}
-	if (prom_radix_disable)
+	if (prom_radix_disable) {
 		prom_debug("Radix disabled from cmdline\n");

Looks like the macro for #prom_debug() should be fixed instead.

Quoted 5 lines
arch/powerpc/kernel/prom_init.c +1 -0
+	}
 }
 
 #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
Signature · 1 line
~Randy
#2 lore raw

On Sun, Apr 8, 2018 at 10:34 PM, Randy Dunlap <[email protected]> wrote= :

Quoted 2 lines · Mathieu Malaterre
Quoted 1 line

In commit 7a22d6321c3d ("powerpc/mm/radix: Update command line parsing f=

or

Quoted 6 lines
Quoted 6 lines

disable_radix") an if statement was added for a possible empty body (prom_debug).

Fix the following warning, treated as error with W=3D1:

arch/powerpc/kernel/prom_init.c:656:46: error: suggest braces around e=

mpty body in an =E2=80=98if=E2=80=99 statement [-Werror=3Dempty-body]

Quoted 7 lines

arch/powerpc/kernel/prom_=

Quoted 7 lines
---
 arch/powerpc/kernel/prom_init.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/kernel/prom_= renamed from arch/powerpc/kernel/prom_init.c +0 -0

init.c

Quoted 4 lines
Quoted 4 lines

index 5ae153b97d0a..f0e802495530 100644

arch/powerpc/kernel/prom_init.c +0 -0
@@ -652,8 +652,9 @@ static void __init early_cmdline_parse(void)
Quoted 8 lines

arch/powerpc/kernel/prom_init.c static void __init early_cmdline_parse(void) · line 656

Quoted 6 lines
arch/powerpc/kernel/prom_init.c +1 -1
              } else
                      prom_radix_disable =3D true;
      }
-     if (prom_radix_disable)
+     if (prom_radix_disable) {
              prom_debug("Radix disabled from cmdline\n");

Looks like the macro for #prom_debug() should be fixed instead.

Well if I try instead:

@@ -101,9 +101,9 @@ int of_workarounds;
} while (0)

#ifdef DEBUG_PROM
-#define prom_debug(x...) prom_printf(x)
+#define prom_debug(x...) do { prom_printf(x); } while (0)
#else
-#define prom_debug(x...)
+#define prom_debug(x...) do { } while (0)
#endif

the checkpatch script returns:

WARNING: Single statement macros should not use a do {} while (0) loop #33: FILE: arch/powerpc/kernel/prom_init.c:104:
+#define prom_debug(x...) do { prom_printf(x); } while (0)

So I suspect we cannot do much better than my original patch unfortunately.

Quoted 9 lines

arch/powerpc/kernel/prom_init.c static void __init early_cmdline_parse(void) · line 660

Quoted 5 lines
arch/powerpc/kernel/prom_init.c +1 -0
+     }
 }
 
 #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)

--
~Randy

#3 lore raw

On Mon, Apr 23, 2018 at 9:31 PM, Mathieu Malaterre <[email protected]> wrote= :

Quoted 1 line

On Sun, Apr 8, 2018 at 10:34 PM, Randy Dunlap <[email protected]> wro=

te:

Quoted 2 lines
Quoted 2 lines · Mathieu Malaterre
Quoted 1 line

In commit 7a22d6321c3d ("powerpc/mm/radix: Update command line parsing =

for

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

disable_radix") an if statement was added for a possible empty body (prom_debug).

Fix the following warning, treated as error with W=3D1:

arch/powerpc/kernel/prom_init.c:656:46: error: suggest braces around =

empty body in an =E2=80=98if=E2=80=99 statement [-Werror=3Dempty-body]

Quoted 7 lines
Quoted 7 lines

arch/powerpc/kernel/prom=

Quoted 7 lines
---
 arch/powerpc/kernel/prom_init.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/kernel/prom= renamed from arch/powerpc/kernel/prom_init.c +0 -0

_init.c

Quoted 29 lines
Quoted 4 lines
Quoted 4 lines

index 5ae153b97d0a..f0e802495530 100644

arch/powerpc/kernel/prom_init.c +0 -0
@@ -652,8 +652,9 @@ static void __init early_cmdline_parse(void)
Quoted 8 lines

arch/powerpc/kernel/prom_init.c static void __init early_cmdline_parse(void) · line 656

Quoted 6 lines
arch/powerpc/kernel/prom_init.c +1 -1
              } else
                      prom_radix_disable =3D true;
      }
-     if (prom_radix_disable)
+     if (prom_radix_disable) {
              prom_debug("Radix disabled from cmdline\n");

Looks like the macro for #prom_debug() should be fixed instead.

Well if I try instead:

(quoted diff) +2 -2
@@ -101,9 +101,9 @@ int of_workarounds;
 } while (0)
 
 #ifdef DEBUG_PROM
-#define prom_debug(x...) prom_printf(x)
+#define prom_debug(x...) do { prom_printf(x); } while (0)
 #else
-#define prom_debug(x...)
+#define prom_debug(x...) do { } while (0)
 #endif
 
 

the checkpatch script returns:

Quoted 6 lines

WARNING: Single statement macros should not use a do {} while (0) loop #33: FILE: arch/powerpc/kernel/prom_init.c:104:
+#define prom_debug(x...) do { prom_printf(x); } while (0)

So I suspect we cannot do much better than my original patch unfortunatel=

y.

Right, it seems I cannot read the correct line number for a warning. An updated patch is coming.

Quoted 9 lines
Quoted 9 lines

arch/powerpc/kernel/prom_init.c static void __init early_cmdline_parse(void) · line 660

Quoted 5 lines
arch/powerpc/kernel/prom_init.c +1 -0
+     }
 }
 
 #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)

--
~Randy

#4 lore raw

PATCH v2 1/1 powerpc/mm/radix: use do/while(0) trick for single statement block

In reply to Mathieu Malaterre

In commit 7a22d6321c3d ("powerpc/mm/radix: Update command line parsing for disable_radix") an if statement was added for a possible empty body (prom_debug).

Fix the following warning, treated as error with W=1:

arch/powerpc/kernel/prom_init.c:656:46: error: suggest braces around empty body in an ‘if’ statement [-Werror=empty-body]

---
v2: update macro directly

 arch/powerpc/kernel/prom_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kernel/prom_init.c +1 -1
index 5ae153b97d0a..7edf3aa5bc6d 100644
@@ -103,7 +103,7 @@ int of_workarounds;
 #ifdef DEBUG_PROM
 #define prom_debug(x...)	prom_printf(x)
 #else
-#define prom_debug(x...)
+#define prom_debug(x...)	do { } while (0)
 #endif
 
 
Signature · 1 line
2.11.0
Acked-by on v2 1/1
#5 lore raw

Re: [PATCH v2] powerpc/mm/radix: use do/while(0) trick for single statement block

Quoted 10 lines · Mathieu Malaterre

In commit 7a22d6321c3d ("powerpc/mm/radix: Update command line parsing for disable_radix") an if statement was added for a possible empty body (prom_debug).

Fix the following warning, treated as error with W=1:

arch/powerpc/kernel/prom_init.c:656:46: error: suggest braces around empty body in an ‘if’ statement [-Werror=empty-body]

Thanks.

Quoted 20 lines

---
v2: update macro directly

 arch/powerpc/kernel/prom_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kernel/prom_init.c +1 -1
index 5ae153b97d0a..7edf3aa5bc6d 100644
@@ -103,7 +103,7 @@ int of_workarounds;
 #ifdef DEBUG_PROM
 #define prom_debug(x...)	prom_printf(x)
 #else
-#define prom_debug(x...)
+#define prom_debug(x...)	do { } while (0)
 #endif
 
 
Signature · 1 line
~Randy
#6 lore raw

Re: [v2] powerpc/mm/radix: use do/while(0) trick for single statement block

In reply to Mathieu Malaterre
Quoted 11 lines · Mathieu Malaterre

In commit 7a22d6321c3d ("powerpc/mm/radix: Update command line parsing for disable_radix") an if statement was added for a possible empty body (prom_debug).

Fix the following warning, treated as error with W=1:

arch/powerpc/kernel/prom_init.c:656:46: error: suggest braces around empty body in an ‘if’ statement [-Werror=empty-body]

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/85aa4b98419d74dd5cc914e0893498

cheers