lkml.org 
[lkml]   [2011]   [Mar]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    Subject[tip:core/urgent] WARN_ON_SMP(): Allow use in if() statements on UP
    Commit-ID:  2092e6be82ec71ecbf5a8ceeef004bbcbdb78812
    Gitweb: http://git.kernel.org/tip/2092e6be82ec71ecbf5a8ceeef004bbcbdb78812
    Author: Steven Rostedt <srostedt@redhat.com>
    AuthorDate: Thu, 17 Mar 2011 15:21:06 -0400
    Committer: Ingo Molnar <mingo@elte.hu>
    CommitDate: Fri, 25 Mar 2011 11:32:09 +0100

    WARN_ON_SMP(): Allow use in if() statements on UP

    Both WARN_ON() and WARN_ON_SMP() should be able to be used in
    an if statement.

    if (WARN_ON_SMP(foo)) { ... }

    Because WARN_ON_SMP() is defined as a do { } while (0) on UP,
    it can not be used this way.

    Convert it to the same form that WARN_ON() is, even when
    CONFIG_SMP is off.

    Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
    Acked-by: Thomas Gleixner <tglx@linutronix.de>
    Acked-by: Peter Zijlstra <peterz@infradead.org>
    Acked-by: Darren Hart <dvhart@linux.intel.com>
    Cc: Lai Jiangshan <laijs@cn.fujitsu.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    LKML-Reference: <20110317192208.444147791@goodmis.org>
    Signed-off-by: Ingo Molnar <mingo@elte.hu>
    ---
    include/asm-generic/bug.h | 28 +++++++++++++++++++++++++++-
    1 files changed, 27 insertions(+), 1 deletions(-)

    diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
    index c2c9ba0..f2d2faf 100644
    --- a/include/asm-generic/bug.h
    +++ b/include/asm-generic/bug.h
    @@ -165,10 +165,36 @@ extern void warn_slowpath_null(const char *file, const int line);
    #define WARN_ON_RATELIMIT(condition, state) \
    WARN_ON((condition) && __ratelimit(state))

    +/*
    + * WARN_ON_SMP() is for cases that the warning is either
    + * meaningless for !SMP or may even cause failures.
    + * This is usually used for cases that we have
    + * WARN_ON(!spin_is_locked(&lock)) checks, as spin_is_locked()
    + * returns 0 for uniprocessor settings.
    + * It can also be used with values that are only defined
    + * on SMP:
    + *
    + * struct foo {
    + * [...]
    + * #ifdef CONFIG_SMP
    + * int bar;
    + * #endif
    + * };
    + *
    + * void func(struct foo *zoot)
    + * {
    + * WARN_ON_SMP(!zoot->bar);
    + *
    + * For CONFIG_SMP, WARN_ON_SMP() should act the same as WARN_ON(),
    + * and should be a nop and return false for uniprocessor.
    + *
    + * if (WARN_ON_SMP(x)) returns true only when CONFIG_SMP is set
    + * and x is true.
    + */
    #ifdef CONFIG_SMP
    # define WARN_ON_SMP(x) WARN_ON(x)
    #else
    -# define WARN_ON_SMP(x) do { } while (0)
    +# define WARN_ON_SMP(x) ({0;})
    #endif

    #endif

    \
     
     \ /
      Last update: 2011-03-25 11:53    [W:0.029 / U:29.768 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site