Re: [PATCH v2 02/13] RDMA/core: Add rdma_udata_to_dev()

Leon Romanovsky
2026-03-02T19:31:00Z

On Thu, Feb 26, 2026 at 09:11:05PM -0400, Jason Gunthorpe wrote:
> Get an ib_device out of a udata so it can be used for debug prints.
>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
> drivers/infiniband/core/ib_core_uverbs.c | 27 ++++++++++++++++++++++++
> include/rdma/uverbs_ioctl.h | 2 ++
> 2 files changed, 29 insertions(+)
>
> diff --git a/drivers/infiniband/core/ib_core_uverbs.c b/drivers/infiniband/core/ib_core_uverbs.c
> index d3836a62a00495..bfe37a9c8a72bf 100644
> --- a/drivers/infiniband/core/ib_core_uverbs.c
> +++ b/drivers/infiniband/core/ib_core_uverbs.c
> @@ -389,3 +389,30 @@ int rdma_user_mmap_entry_insert(struct ib_ucontext *ucontext,
> U32_MAX);
> }
> EXPORT_SYMBOL(rdma_user_mmap_entry_insert);
> +
> +/**
> + * rdma_udata_to_dev - Get a ib_device from a udata
> + * @udata: The system calls ib_udata struct
> + *
> + * The struct ib_device that is handling the uverbs call. Must not be called if
> + * udata is NULL. The result can be NULL.
> + */
> +struct ib_device *rdma_udata_to_dev(struct ib_udata *udata)
> +{
> + struct uverbs_attr_bundle *bundle =
> + rdma_udata_to_uverbs_attr_bundle(udata);
> +
> + lockdep_assert_held(&bundle->ufile->device->disassociate_srcu);
> +
> + if (bundle->context)
> + return bundle->context->device;
> +
> + /*
> + * If the context hasn't been created yet use the ufile's dev, but it
> + * might be NULL if we are racing with disassociate.
> + */
> + return srcu_dereference(bundle->ufile->device->ib_dev,
> + &bundle->ufile->device->disassociate_srcu);
> +}
> +EXPORT_SYMBOL(rdma_udata_to_dev);

Thanks for this function, looks great, however I wonder about use of it
in debug prints. What about changing:

+ ibdev_dbg(
+ rdma_udata_to_dev(udata),
...

to be something
+ udata_dbg(
+ udata,
....

Together with keeping this rdma_udata_to_dev() function.

Thanks