Re: halt/reset on assert?

2011-04-07 Thread Benjamin Herrenschmidt
On Thu, 2011-04-07 at 12:04 -0500, kevin diggs wrote:
> On Thu, Apr 7, 2011 at 2:55 AM, Benjamin Herrenschmidt
>  wrote:
> > On Wed, 2011-04-06 at 14:01 +0100, Evan Lavelle wrote:
> >> #define MY_ASSERT(expr) if(!(expr)) BUG()
> >
> > Make it
> >
> > #define MY_ASSERT(expr) do { if  } while(0)
> >
> > To ensure it has proper single statement semantics in C.
> >
> So THAT'S why they do this!! Now I just have to figure out what
> 'proper single statement semantics' means!

Thing what happens without the do { ... } while(0) if you have code
that looks like:

if (enable_debug)
MY_ASSERT(foo);
else
something_else;

Ben.


___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: halt/reset on assert?

2011-04-07 Thread kevin diggs
On Thu, Apr 7, 2011 at 2:55 AM, Benjamin Herrenschmidt
 wrote:
> On Wed, 2011-04-06 at 14:01 +0100, Evan Lavelle wrote:
>> #define MY_ASSERT(expr) if(!(expr)) BUG()
>
> Make it
>
> #define MY_ASSERT(expr) do { if  } while(0)
>
> To ensure it has proper single statement semantics in C.
>
So THAT'S why they do this!! Now I just have to figure out what
'proper single statement semantics' means!

THANKS!!!

kevin

> Cheers,
> Ben.
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: halt/reset on assert?

2011-04-07 Thread Benjamin Herrenschmidt
On Wed, 2011-04-06 at 14:01 +0100, Evan Lavelle wrote:
> #define MY_ASSERT(expr) if(!(expr)) BUG()

Make it

#define MY_ASSERT(expr) do { if  } while(0)

To ensure it has proper single statement semantics in C.

Cheers,
Ben.


___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: halt/reset on assert?

2011-04-06 Thread Evan Lavelle

Hi Andreas -

that's great; thanks. I'm on 2.4.4, which doesn't have BUG_ON. The right 
way for 2.4.4 turns out to be


#define MY_ASSERT(expr) if(!(expr)) BUG()

-Evan
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: halt/reset on assert?

2011-04-01 Thread Andreas Schwab
Evan Lavelle  writes:

> I'd like to use an assert macro in a device driver for an MPC870 using
> ppcboot; something like:
>
> #define MY_ASSERT(expr) \
>do { \
>   if(!(expr)) { \
>  printk(\
> KERN_EMERG  \
> "assertion failure: %s, line %d\n", \
> __FILE__, __LINE__);\
>  asm(--ppc halt/reset?) \
>   } \
>} while(0)
>
> However, I've got no idea how to halt or reset the processor here. Anyone
> happen to know?

#define MY_ASSERT(expr) BUG_ON(!(expr))

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: halt/reset on assert?

2011-04-01 Thread Andreas Schwab
Evan Lavelle  writes:

> I'd like to use an assert macro in a device driver for an MPC870 using
> ppcboot; something like:
>
> #define MY_ASSERT(expr) \
>do { \
>   if(!(expr)) { \
>  printk(\
> KERN_EMERG  \
> "assertion failure: %s, line %d\n", \
> __FILE__, __LINE__);\
>  asm(--ppc halt/reset?) \
>   } \
>} while(0)
>
> However, I've got no idea how to halt or reset the processor here. Anyone
> happen to know?

#define MY_ASSERT(expr) BUG(!(expr))

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


halt/reset on assert?

2011-04-01 Thread Evan Lavelle
I'd like to use an assert macro in a device driver for an MPC870 using 
ppcboot; something like:


#define MY_ASSERT(expr) \
   do { \
  if(!(expr)) { \
 printk(\
KERN_EMERG  \
"assertion failure: %s, line %d\n", \
__FILE__, __LINE__);\
 asm(--ppc halt/reset?) \
  } \
   } while(0)

However, I've got no idea how to halt or reset the processor here. 
Anyone happen to know?


Thanks -

Evan
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev