Skip to contentSkip to conversation

powerpc/interrupt: Put braces around empty body in an 'if' statement

PATCH In review Souptick Joarder 3 participants 4 messages Jun 19, 2022 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/interrupt: Put braces around empty body in an 'if' statement

From: "Souptick Joarder (HPE)" <[email protected]>

Kernel test robot throws warning ->

arch/powerpc/kernel/interrupt.c:
In function 'interrupt_exit_kernel_prepare':

Quoted 1 line
Quoted 1 line

arch/powerpc/kernel/interrupt.c:542:55: warning: suggest

braces around empty body in an 'if' statement [-Wempty-body]

     542 |                 CT_WARN_ON(ct_state() == CONTEXT_USER);

Fix it by adding braces.

---
 arch/powerpc/kernel/interrupt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/kernel/interrupt.c +2 -1
index 784ea3289c84..b8a918bab48f 100644
@@ -538,8 +538,9 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs)
 	 * CT_WARN_ON comes here via program_check_exception,
 	 * so avoid recursion.
 	 */
-	if (TRAP(regs) != INTERRUPT_PROGRAM)
+	if (TRAP(regs) != INTERRUPT_PROGRAM) {
 		CT_WARN_ON(ct_state() == CONTEXT_USER);
+	}
 
 	kuap = kuap_get_and_assert_locked();
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 10 lines · Souptick Joarder

From: "Souptick Joarder (HPE)" <[email protected]>

Kernel test robot throws warning ->

arch/powerpc/kernel/interrupt.c:
In function 'interrupt_exit_kernel_prepare':

Quoted 1 line
Quoted 1 line

arch/powerpc/kernel/interrupt.c:542:55: warning: suggest

braces around empty body in an 'if' statement [-Wempty-body]

     542 |                 CT_WARN_ON(ct_state() == CONTEXT_USER);

That must be when CONFIG_CONTEXT_TRACKING_USER is not set/enabled. Can you confirm that?

Then the preferable fix would be in <linux/context_tracking.h>:

change
#define CT_WARN_ON(cond)

to either an empty do-while loop or a static inline function.

(adding Frederic to Cc:)

Quoted 24 lines

Fix it by adding braces.

---
 arch/powerpc/kernel/interrupt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/kernel/interrupt.c +2 -1
index 784ea3289c84..b8a918bab48f 100644
@@ -538,8 +538,9 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs)
 	 * CT_WARN_ON comes here via program_check_exception,
 	 * so avoid recursion.
 	 */
-	if (TRAP(regs) != INTERRUPT_PROGRAM)
+	if (TRAP(regs) != INTERRUPT_PROGRAM) {
 		CT_WARN_ON(ct_state() == CONTEXT_USER);
+	}
 
 	kuap = kuap_get_and_assert_locked();
 
Signature · 1 line
~Randy
#2 lore raw
Quoted 11 lines · Randy Dunlap
Quoted 7 lines · Souptick Joarder

From: "Souptick Joarder (HPE)" <[email protected]>

Kernel test robot throws warning ->

arch/powerpc/kernel/interrupt.c:
In function 'interrupt_exit_kernel_prepare':

Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

arch/powerpc/kernel/interrupt.c:542:55: warning: suggest

braces around empty body in an 'if' statement [-Wempty-body]

     542 |                 CT_WARN_ON(ct_state() == CONTEXT_USER);

That must be when CONFIG_CONTEXT_TRACKING_USER is not set/enabled. Can you confirm that?

Yes, CONFIG_CONTEXT_TRACKING_USER is not set.

Quoted 37 lines

Then the preferable fix would be in <linux/context_tracking.h>:

change
#define CT_WARN_ON(cond)

to either an empty do-while loop or a static inline function.

(adding Frederic to Cc:)

Quoted 14 lines

Fix it by adding braces.

---
 arch/powerpc/kernel/interrupt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/kernel/interrupt.c +0 -0
index 784ea3289c84..b8a918bab48f 100644

arch/powerpc/kernel/interrupt.c notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs) · line 546

Quoted 10 lines
arch/powerpc/kernel/interrupt.c +2 -1
@@ -538,8 +538,9 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs)
       * CT_WARN_ON comes here via program_check_exception,
       * so avoid recursion.
       */
-     if (TRAP(regs) != INTERRUPT_PROGRAM)
+     if (TRAP(regs) != INTERRUPT_PROGRAM) {
              CT_WARN_ON(ct_state() == CONTEXT_USER);
+     }
 
      kuap = kuap_get_and_assert_locked();
 

--
~Randy

#3 lore raw
In reply to Souptick Joarder

Le 19/06/2022 à 05:11, Souptick Joarder a écrit :

Quoted 4 lines

From: "Souptick Joarder (HPE)" <[email protected]>

Kernel test robot throws warning ->

Quoted 8 lines

arch/powerpc/kernel/interrupt.c:
In function 'interrupt_exit_kernel_prepare':

Quoted 1 line
Quoted 1 line

arch/powerpc/kernel/interrupt.c:542:55: warning: suggest

braces around empty body in an 'if' statement [-Wempty-body]

      542 |                 CT_WARN_ON(ct_state() == CONTEXT_USER);

Fix it by adding braces.

There must be no braces for single 'if' statement , see
https://docs.kernel.org/process/coding-style.html#placing-braces-and-spaces

The problem is likely that CT_WARN_ON() is empty in some CONFIGs. You have to fix it, for instance by changing it to a "do { } while (0)"

Quoted 25 lines
---
  arch/powerpc/kernel/interrupt.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/kernel/interrupt.c +2 -2
index 784ea3289c84..b8a918bab48f 100644
@@ -538,8 +538,9 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs)
          * CT_WARN_ON comes here via program_check_exception,
          * so avoid recursion.
          */
-       if (TRAP(regs) != INTERRUPT_PROGRAM)
+       if (TRAP(regs) != INTERRUPT_PROGRAM) {
                 CT_WARN_ON(ct_state() == CONTEXT_USER);
+       }
 
         kuap = kuap_get_and_assert_locked();
 
--

2.25.1