[dpdk-dev,1/2] Fix container_of() macro to work with const members
Checks
Commit Message
This fixes the usage of structure members that are declared const to get
a pointer to the embedding parent structure.
Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
lib/librte_eal/common/include/rte_common.h | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
Comments
On Tue, Feb 14, 2017 at 3:36 PM, Jan Blunck <jblunck@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@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
>
On Mon, Feb 27, 2017 at 03:28:14PM +0100, Jan Blunck wrote:
> On Tue, Feb 14, 2017 at 3:36 PM, Jan Blunck <jblunck@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?
>
Looks ok to me.
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
2017-02-27 15:14, Bruce Richardson:
> On Mon, Feb 27, 2017 at 03:28:14PM +0100, Jan Blunck wrote:
> > On Tue, Feb 14, 2017 at 3:36 PM, Jan Blunck <jblunck@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?
> >
> Looks ok to me.
>
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Applied, thanks
@@ -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