[dpdk-dev] [PATCH 1/2] Fix container_of() macro to work with const members

Jan Blunck jblunck at infradead.org
Mon Feb 27 15:28:14 CET 2017


On Tue, Feb 14, 2017 at 3:36 PM, Jan Blunck <jblunck at infradead.org> wrote:
> This fixes the usage of structure members that are declared const to get
> a pointer to the embedding parent structure.

Ping. Is anyone willing to review this?

Thanks,
Jan

>
> Signed-off-by: Jan Blunck <jblunck at infradead.org>
> ---
>  lib/librte_eal/common/include/rte_common.h | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
> index 8dda3e2..c421708 100644
> --- a/lib/librte_eal/common/include/rte_common.h
> +++ b/lib/librte_eal/common/include/rte_common.h
> @@ -347,8 +347,9 @@ rte_bsf32(uint32_t v)
>   */
>  #ifndef container_of
>  #define container_of(ptr, type, member)        __extension__ ({                \
> -                       typeof(((type *)0)->member) *_ptr = (ptr);      \
> -                       (type *)(((char *)_ptr) - offsetof(type, member)); })
> +                       const typeof(((type *)0)->member) *_ptr = (ptr); \
> +                       (type *)(((uintptr_t)_ptr) - offsetof(type, member)); \
> +               })
>  #endif
>
>  #define _RTE_STR(x) #x
> --
> 2.7.4
>


More information about the dev mailing list