Skip to content

Commit 43f003b

Browse files
chleroympe
authored andcommitted
powerpc: Refactor BUG/WARN macros
BUG(), WARN() and friends are using a similar inline assembly to implement various traps with various flags. Lets refactor via a new BUG_ENTRY() macro. Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/c19a82b37677ace0eebb0dc8c2120373c29c8dd1.1566219503.git.christophe.leroy@c-s.fr
1 parent 98ba8e8 commit 43f003b

File tree

1 file changed

+15
-26
lines changed
  • arch/powerpc/include/asm

1 file changed

+15
-26
lines changed

arch/powerpc/include/asm/bug.h

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,23 @@
4949
".previous\n"
5050
#endif
5151

52+
#define BUG_ENTRY(insn, flags, ...) \
53+
__asm__ __volatile__( \
54+
"1: " insn "\n" \
55+
_EMIT_BUG_ENTRY \
56+
: : "i" (__FILE__), "i" (__LINE__), \
57+
"i" (flags), \
58+
"i" (sizeof(struct bug_entry)), \
59+
##__VA_ARGS__)
60+
5261
/*
5362
* BUG_ON() and WARN_ON() do their best to cooperate with compile-time
5463
* optimisations. However depending on the complexity of the condition
5564
* some compiler versions may not produce optimal results.
5665
*/
5766

5867
#define BUG() do { \
59-
__asm__ __volatile__( \
60-
"1: twi 31,0,0\n" \
61-
_EMIT_BUG_ENTRY \
62-
: : "i" (__FILE__), "i" (__LINE__), \
63-
"i" (0), "i" (sizeof(struct bug_entry))); \
68+
BUG_ENTRY("twi 31, 0, 0", 0); \
6469
unreachable(); \
6570
} while (0)
6671

@@ -69,37 +74,21 @@
6974
if (x) \
7075
BUG(); \
7176
} else { \
72-
__asm__ __volatile__( \
73-
"1: "PPC_TLNEI" %4,0\n" \
74-
_EMIT_BUG_ENTRY \
75-
: : "i" (__FILE__), "i" (__LINE__), "i" (0), \
76-
"i" (sizeof(struct bug_entry)), \
77-
"r" ((__force long)(x))); \
77+
BUG_ENTRY(PPC_TLNEI " %4, 0", 0, "r" ((__force long)(x))); \
7878
} \
7979
} while (0)
8080

81-
#define __WARN_FLAGS(flags) do { \
82-
__asm__ __volatile__( \
83-
"1: twi 31,0,0\n" \
84-
_EMIT_BUG_ENTRY \
85-
: : "i" (__FILE__), "i" (__LINE__), \
86-
"i" (BUGFLAG_WARNING|(flags)), \
87-
"i" (sizeof(struct bug_entry))); \
88-
} while (0)
81+
#define __WARN_FLAGS(flags) BUG_ENTRY("twi 31, 0, 0", BUGFLAG_WARNING | (flags))
8982

9083
#define WARN_ON(x) ({ \
9184
int __ret_warn_on = !!(x); \
9285
if (__builtin_constant_p(__ret_warn_on)) { \
9386
if (__ret_warn_on) \
9487
__WARN(); \
9588
} else { \
96-
__asm__ __volatile__( \
97-
"1: "PPC_TLNEI" %4,0\n" \
98-
_EMIT_BUG_ENTRY \
99-
: : "i" (__FILE__), "i" (__LINE__), \
100-
"i" (BUGFLAG_WARNING|BUGFLAG_TAINT(TAINT_WARN)),\
101-
"i" (sizeof(struct bug_entry)), \
102-
"r" (__ret_warn_on)); \
89+
BUG_ENTRY(PPC_TLNEI " %4, 0", \
90+
BUGFLAG_WARNING | BUGFLAG_TAINT(TAINT_WARN), \
91+
"r" (__ret_warn_on)); \
10392
} \
10493
unlikely(__ret_warn_on); \
10594
})

0 commit comments

Comments
 (0)