Re: [PATCH for-next v2 2/3] IB/verbs: add helper function rdma_udata_to_drv_context

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jan 28, 2019 at 12:01:06PM -0700, Jason Gunthorpe wrote:
> On Mon, Jan 28, 2019 at 12:12:23PM +0200, Shamir Rabinovitch wrote:
> > Helper function to get driver's context out of ib_udata wrapped
> > in uverbs_attr_bundle for uer objects or NULL for kernel objects.
> > 
> > Signed-off-by: Shamir Rabinovitch <shamir.rabinovitch@xxxxxxxxxx>
> >  include/rdma/ib_verbs.h | 14 ++++++++++++++
> >  1 file changed, 14 insertions(+)
> > 
> > diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
> > index 94b6e1dd4dab..fb4d078d6db3 100644
> > +++ b/include/rdma/ib_verbs.h
> > @@ -4264,4 +4264,18 @@ static inline struct ib_device *rdma_device_to_ibdev(struct device *device)
> >   */
> >  #define rdma_device_to_drv_device(dev, drv_dev_struct, ibdev_member)           \
> >  	container_of(rdma_device_to_ibdev(dev), drv_dev_struct, ibdev_member)
> > +
> > +/**
> > + * rdma_udata_to_drv_context - Helper macro to get the driver's context out of
> > + *                             ib_udata which is embadded in uverbs_attr_bundle.
> > + *
> > + * NOTE: This macro return NULL for kernel objects and valid driver context for
> > + * user objects.
> 
> Actually at this point I think this just can't fail if udata is set,
> so lets just say that:
> 
> /*
>  * If udata is not NULL this cannot fail. Otherwise a NULL udata will result
>  * in a NULL ucontext pointer. Callers can rely on !NULL ucontext to show the
>  * op is being called as part of a user system call.
>  */
> #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)
> 
> And get rid of the rdma_get_ucontext helper function, umem can just
> inspect udata->context itself and fail with EIO if NULL.
> 
> Jason

OK. Change accordingly & skip previous mail.



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux