lkml.org 
[lkml]   [2021]   [Nov]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 01/17] linux/container_of.h: Add memberof(T, m)
    Date
    Many xxxof_member() macros make use of the same construction
    to refer to a member of a struct
    without needing a variable of the struct type.

    memberof(T, m)
    simplifies all of those,
    avoids possible mistakes in repetition,
    adds a meaningful name to the construction,
    and improves readability by avoiding too many parentheses together.

    Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    Cc: Miguel Ojeda <ojeda@kernel.org>
    Cc: Nick Desaulniers <ndesaulniers@google.com>
    Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
    Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
    Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
    Cc: Mike Rapoport <rppt@linux.ibm.com>
    Cc: Corey Minyard <cminyard@mvista.com>
    Cc: Christian Brauner <christian.brauner@ubuntu.com>
    Cc: Arnd Bergmann <arnd@arndb.de>
    Cc: Kees Cook <keescook@chromium.org>
    ---
    include/linux/container_of.h | 3 +++
    1 file changed, 3 insertions(+)

    diff --git a/include/linux/container_of.h b/include/linux/container_of.h
    index 2f4944b791b8..199c78a3bf29 100644
    --- a/include/linux/container_of.h
    +++ b/include/linux/container_of.h
    @@ -5,6 +5,9 @@
    #include <linux/build_bug.h>
    #include <linux/err.h>

    +
    +#define memberof(T, m) (((T *) NULL)->m)
    +
    #define typeof_member(T, m) typeof(((T*)0)->m)

    /**
    --
    2.33.1
    \
     
     \ /
      Last update: 2021-11-19 12:39    [W:2.808 / U:0.024 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site