IB/verbs: avoid nested container_of()
authorArnd Bergmann <arnd@arndb.de>
Mon, 26 Oct 2020 16:15:39 +0000 (17:15 +0100)
committerJason Gunthorpe <jgg@nvidia.com>
Wed, 28 Oct 2020 13:06:51 +0000 (10:06 -0300)
commitbfb972c5e1cba88c93912f271ed5ecc114e31431
tree8bed4363ea956a088b52937cf8dacce1a67b420e
parentb898d5c50cab1f985e77d053eb5c4d2c4a7694ae
IB/verbs: avoid nested container_of()

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")
Link: https://lore.kernel.org/r/20201026161549.3709175-1-arnd@kernel.org
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
include/rdma/uverbs_ioctl.h