* [PATCH] IB/verbs: avoid nested container_of()
@ 2020-10-26 16:15 Arnd Bergmann
2020-10-28 13:30 ` Jason Gunthorpe
0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2020-10-26 16:15 UTC (permalink / raw)
To: Doug Ledford, Jason Gunthorpe, Shamir Rabinovitch
Cc: Arnd Bergmann, Jason Gunthorpe, Leon Romanovsky, Yishai Hadas,
Michael Guralnik, Gustavo A. R. Silva, linux-rdma, linux-kernel
From: Arnd Bergmann <arnd@arndb.de>
Nested container_of() calls work correctly but cause a warning when
building with W=2. Invoking it from an inline function like in
drivers/infiniband/hw/mlx5/mlx5_ib.h means we get hundreds of
warnings like:
include/linux/kernel.h:852:8: warning: declaration of '__mptr' shadows a previous local [-Wshadow]
852 | void *__mptr = (void *)(ptr); \
| ^~~~~~
include/rdma/uverbs_ioctl.h:651:11: note: in expansion of macro 'container_of'
651 | (udata ? container_of(container_of(udata, struct uverbs_attr_bundle, \
| ^~~~~~~~~~~~
include/rdma/uverbs_ioctl.h:651:24: note: in expansion of macro 'container_of'
651 | (udata ? container_of(container_of(udata, struct uverbs_attr_bundle, \
| ^~~~~~~~~~~~
drivers/infiniband/hw/mthca/mthca_qp.c:564:35: note: in expansion of macro 'rdma_udata_to_drv_context'
564 | struct mthca_ucontext *context = rdma_udata_to_drv_context(
| ^~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/kernel.h:852:8: note: shadowed declaration is here
852 | void *__mptr = (void *)(ptr); \
| ^~~~~~
include/rdma/uverbs_ioctl.h:651:11: note: in expansion of macro 'container_of'
651 | (udata ? container_of(container_of(udata, struct uverbs_attr_bundle, \
| ^~~~~~~~~~~~
drivers/infiniband/hw/mthca/mthca_qp.c:564:35: note: in expansion of macro 'rdma_udata_to_drv_context'
564 | struct mthca_ucontext *context = rdma_udata_to_drv_context(
| ^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from <command-line>:
include/linux/kernel.h:852:8: warning: declaration of '__mptr' shadows a previous local [-Wshadow]
852 | void *__mptr = (void *)(ptr); \
| ^~~~~~
Rewrite the macro to use an inline function internally, which makes
it more readable and reduces the amount of useless output from
make W=2.
Fixes: 730623f4a56f ("IB/verbs: Add helper function rdma_udata_to_drv_context")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
include/rdma/uverbs_ioctl.h | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/include/rdma/uverbs_ioctl.h b/include/rdma/uverbs_ioctl.h
index b00270c72740..bf167ef6c688 100644
--- a/include/rdma/uverbs_ioctl.h
+++ b/include/rdma/uverbs_ioctl.h
@@ -647,12 +647,15 @@ static inline bool uverbs_attr_is_valid(const struct uverbs_attr_bundle *attrs_b
* 'ucontext'.
*
*/
-#define rdma_udata_to_drv_context(udata, drv_dev_struct, member) \
- (udata ? container_of(container_of(udata, struct uverbs_attr_bundle, \
- driver_udata) \
- ->context, \
- drv_dev_struct, member) : \
- (drv_dev_struct *)NULL)
+static inline struct uverbs_attr_bundle *
+rdma_udata_to_uverbs_attr_bundle(struct ib_udata *udata)
+{
+ return container_of(udata, struct uverbs_attr_bundle, driver_udata);
+}
+
+#define rdma_udata_to_drv_context(udata, drv_dev_struct, member) \
+ (udata ? container_of(rdma_udata_to_uverbs_attr_bundle(udata)->context, \
+ drv_dev_struct, member) : (drv_dev_struct *)NULL)
#define IS_UVERBS_COPY_ERR(_ret) ((_ret) && (_ret) != -ENOENT)
--
2.27.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] IB/verbs: avoid nested container_of()
2020-10-26 16:15 [PATCH] IB/verbs: avoid nested container_of() Arnd Bergmann
@ 2020-10-28 13:30 ` Jason Gunthorpe
0 siblings, 0 replies; 2+ messages in thread
From: Jason Gunthorpe @ 2020-10-28 13:30 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Doug Ledford, Shamir Rabinovitch, Arnd Bergmann, Leon Romanovsky,
Yishai Hadas, Michael Guralnik, Gustavo A. R. Silva, linux-rdma,
linux-kernel
On Mon, Oct 26, 2020 at 05:15:39PM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> Nested container_of() calls work correctly but cause a warning when
> building with W=2. Invoking it from an inline function like in
> drivers/infiniband/hw/mlx5/mlx5_ib.h means we get hundreds of
> warnings like:
>
> include/linux/kernel.h:852:8: warning: declaration of '__mptr' shadows a previous local [-Wshadow]
> 852 | void *__mptr = (void *)(ptr); \
> | ^~~~~~
> include/rdma/uverbs_ioctl.h:651:11: note: in expansion of macro 'container_of'
> 651 | (udata ? container_of(container_of(udata, struct uverbs_attr_bundle, \
> | ^~~~~~~~~~~~
> include/rdma/uverbs_ioctl.h:651:24: note: in expansion of macro 'container_of'
> 651 | (udata ? container_of(container_of(udata, struct uverbs_attr_bundle, \
> | ^~~~~~~~~~~~
> drivers/infiniband/hw/mthca/mthca_qp.c:564:35: note: in expansion of macro 'rdma_udata_to_drv_context'
> 564 | struct mthca_ucontext *context = rdma_udata_to_drv_context(
> | ^~~~~~~~~~~~~~~~~~~~~~~~~
> include/linux/kernel.h:852:8: note: shadowed declaration is here
> 852 | void *__mptr = (void *)(ptr); \
> | ^~~~~~
> include/rdma/uverbs_ioctl.h:651:11: note: in expansion of macro 'container_of'
> 651 | (udata ? container_of(container_of(udata, struct uverbs_attr_bundle, \
> | ^~~~~~~~~~~~
> drivers/infiniband/hw/mthca/mthca_qp.c:564:35: note: in expansion of macro 'rdma_udata_to_drv_context'
> 564 | struct mthca_ucontext *context = rdma_udata_to_drv_context(
> | ^~~~~~~~~~~~~~~~~~~~~~~~~
> In file included from <command-line>:
> include/linux/kernel.h:852:8: warning: declaration of '__mptr' shadows a previous local [-Wshadow]
> 852 | void *__mptr = (void *)(ptr); \
> | ^~~~~~
>
> Rewrite the macro to use an inline function internally, which makes
> it more readable and reduces the amount of useless output from
> make W=2.
>
> Fixes: 730623f4a56f ("IB/verbs: Add helper function rdma_udata_to_drv_context")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> include/rdma/uverbs_ioctl.h | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
Applied to rdma for-next, thanks
Jason
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-10-28 22:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-26 16:15 [PATCH] IB/verbs: avoid nested container_of() Arnd Bergmann
2020-10-28 13:30 ` Jason Gunthorpe
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).