lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAK8P3a0asgPE3oh6fagLT434zTw6xbpqk-ioG1XCJcM2GOsHVQ@mail.gmail.com>
Date:   Sun, 21 Nov 2021 14:31:49 +0100
From:   Arnd Bergmann <arnd@...db.de>
To:     Alejandro Colomar <alx.manpages@...il.com>
Cc:     LKML <linux-kernel@...r.kernel.org>,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        Arnd Bergmann <arnd@...db.de>,
        Alexey Dobriyan <adobriyan@...il.com>,
        Jani Nikula <jani.nikula@...ux.intel.com>,
        Rasmus Villemoes <linux@...musvillemoes.dk>,
        Kees Cook <keescook@...omium.org>,
        Joe Perches <joe@...ches.com>
Subject: Re: [PATCH v2 08/20] Implement container_of_safe() in terms of container_of()

On Sat, Nov 20, 2021 at 2:00 PM Alejandro Colomar
<alx.manpages@...il.com> wrote:
>
> There's no more a need for the temporary variable __mptr,
> since now it's only passed to functions that accept a 'const void *',
> and everything can convert automatically to it,
> reducing the need for the cast too.

The purpose of the temporary variable is to avoid evaluating the macro
multiple times, this is still required.

>   * If IS_ERR_OR_NULL(ptr), ptr is returned unchanged.
>   */
> -#define container_of_safe(ptr, type, member) ({                                \
> -       void *__mptr = (void *)(ptr);                                   \
> -       static_assert(__same_type(*(ptr), ((type *)0)->member) ||       \
> -                     __same_type(*(ptr), void),                        \
> -                     "pointer type mismatch in container_of_safe()");  \
> -       IS_ERR_OR_NULL(__mptr) ? ERR_CAST(__mptr) :                     \
> -               ((type *)(__mptr - offsetof(type, member))); })
> +#define container_of_safe(ptr, type, member)                           \
> +       (IS_ERR_OR_NULL(ptr) ? ERR_CAST(ptr) : container_of(type, member))

It's possible that you may find a way to improve this macro using
__auto_type, as a way to reduce the macro expansion further.

        Arnd

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ