* [dpdk-dev] [PATCH 1/2] Fix container_of() macro to work with const members
@ 2017-02-14 14:36 Jan Blunck
2017-02-14 14:36 ` [dpdk-dev] [PATCH 2/2] Ensure constness of target pointer type Jan Blunck
2017-02-27 14:28 ` [dpdk-dev] [PATCH 1/2] Fix container_of() macro to work with const members Jan Blunck
0 siblings, 2 replies; 5+ messages in thread
From: Jan Blunck @ 2017-02-14 14:36 UTC (permalink / raw)
To: dev
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(-)
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* [dpdk-dev] [PATCH 2/2] Ensure constness of target pointer type
2017-02-14 14:36 [dpdk-dev] [PATCH 1/2] Fix container_of() macro to work with const members Jan Blunck
@ 2017-02-14 14:36 ` Jan Blunck
2017-02-27 14:28 ` [dpdk-dev] [PATCH 1/2] Fix container_of() macro to work with const members Jan Blunck
1 sibling, 0 replies; 5+ messages in thread
From: Jan Blunck @ 2017-02-14 14:36 UTC (permalink / raw)
To: dev
This adds a check to ensure that the container_of() macro is not used to
cast away (remove) constness.
Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
lib/librte_eal/common/include/rte_common.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index c421708..e057f6e 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -348,6 +348,8 @@ rte_bsf32(uint32_t v)
#ifndef container_of
#define container_of(ptr, type, member) __extension__ ({ \
const typeof(((type *)0)->member) *_ptr = (ptr); \
+ __attribute__((unused)) type *_target_ptr = \
+ (type *)(ptr); \
(type *)(((uintptr_t)_ptr) - offsetof(type, member)); \
})
#endif
--
2.7.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [dpdk-dev] [PATCH 1/2] Fix container_of() macro to work with const members
2017-02-14 14:36 [dpdk-dev] [PATCH 1/2] Fix container_of() macro to work with const members Jan Blunck
2017-02-14 14:36 ` [dpdk-dev] [PATCH 2/2] Ensure constness of target pointer type Jan Blunck
@ 2017-02-27 14:28 ` Jan Blunck
2017-02-27 15:14 ` Bruce Richardson
1 sibling, 1 reply; 5+ messages in thread
From: Jan Blunck @ 2017-02-27 14:28 UTC (permalink / raw)
To: dev
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
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [dpdk-dev] [PATCH 1/2] Fix container_of() macro to work with const members
2017-02-27 14:28 ` [dpdk-dev] [PATCH 1/2] Fix container_of() macro to work with const members Jan Blunck
@ 2017-02-27 15:14 ` Bruce Richardson
2017-03-08 14:01 ` Thomas Monjalon
0 siblings, 1 reply; 5+ messages in thread
From: Bruce Richardson @ 2017-02-27 15:14 UTC (permalink / raw)
To: Jan Blunck; +Cc: dev
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>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [dpdk-dev] [PATCH 1/2] Fix container_of() macro to work with const members
2017-02-27 15:14 ` Bruce Richardson
@ 2017-03-08 14:01 ` Thomas Monjalon
0 siblings, 0 replies; 5+ messages in thread
From: Thomas Monjalon @ 2017-03-08 14:01 UTC (permalink / raw)
To: Jan Blunck; +Cc: dev, Bruce Richardson
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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-03-08 14:01 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-14 14:36 [dpdk-dev] [PATCH 1/2] Fix container_of() macro to work with const members Jan Blunck
2017-02-14 14:36 ` [dpdk-dev] [PATCH 2/2] Ensure constness of target pointer type Jan Blunck
2017-02-27 14:28 ` [dpdk-dev] [PATCH 1/2] Fix container_of() macro to work with const members Jan Blunck
2017-02-27 15:14 ` Bruce Richardson
2017-03-08 14:01 ` Thomas Monjalon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).