Re: [PATCH 0/6] use BUG_ON correctly

WANG Cong
2011-01-27T07:42:11Z

On Thu, 27 Jan 2011 15:19:05 +0800, Coly Li wrote:
>>>>
>>> Could you please to identify a piece of kernel code which provides an
>>> example as the condition you mentioned ? So I can have a look firstly.
>>
>> # line filename / context / line
>> 1 35 arch/mips/include/asm/bug.h<<HAVE_ARCH_BUG_ON>>
>> #define HAVE_ARCH_BUG_ON
>> 2 115 arch/powerpc/include/asm/bug.h<<HAVE_ARCH_BUG_ON>>
>> #define HAVE_ARCH_BUG_ON
>
> I don't find arch dependent implementation of BUG_ON from the above
> files. Do I miss something ?

arch/mips/include/asm/bug.h:

static inline void __BUG_ON(unsigned long condition)
{
if (__builtin_constant_p(condition)) {
if (condition)
BUG();
else
return;
}
__asm__ __volatile__("tne $0, %0, %1"
: : "r" (condition), "i" (BRK_BUG));
}

#define BUG_ON(C) __BUG_ON((unsigned long)(C))

#define HAVE_ARCH_BUG_ON

arch/powerpc/include/asm/bug.h:

#define BUG_ON(x) do { \
if (__builtin_constant_p(x)) { \
if (x) \
BUG(); \
} else { \
__asm__ __volatile__( \
"1: "PPC_TLNEI" %4,0\n" \
_EMIT_BUG_ENTRY \
: : "i" (__FILE__), "i" (__LINE__), "i" (0), \
"i" (sizeof(struct bug_entry)), \
"r" ((__force long)(x))); \
} \
} while (0)