Re: [PATCH 1/8] verbs: Always allocate a verbs_context

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

 



On Thu, Jan 11, 2018 at 11:14:33PM +0530, Devesh Sharma wrote:
> On Wed, Jan 10, 2018 at 11:04 PM, Jason Gunthorpe <jgg@xxxxxxxxxxxx> wrote:
> > On Wed, Jan 10, 2018 at 11:16:20AM +0530, Devesh Sharma wrote:
> >
> >> > +/*
> >> > + * Allocate and initialize a context structure. This is called to create the
> >> > + * driver wrapper, and context_offset is the number of bytes into the wrapper
> >> > + * structure where the verbs_context starts.
> >> > + */
> >> > +void *_verbs_init_and_alloc_context(struct ibv_device *device, int cmd_fd,
> >> > +                                   size_t alloc_size,
> >> > +                                   struct verbs_context *context_offset)
> >> > +{
> >> > +       void *drv_context;
> >> > +       struct verbs_context *context;
> >> > +
> >> > +       drv_context = calloc(1, alloc_size);
> >> > +       if (!drv_context) {
> >> > +               errno = ENOMEM;
> >> > +               close(cmd_fd);
> >> > +               return NULL;
> >> > +       }
> >> > +
> >> > +       context = (struct verbs_context *)((uint8_t *)drv_context +
> >> > +                                          (uintptr_t)context_offset);
> >>
> >> A wrapper macro would do better here?

> > Thing is, this is the only place that does this calculation and it is
> > intimately tied to the definition of the
> > verbs_init_and_alloc_context() macro, so it really is unique and
> > special to this function.
> 
> If that is the case I don't mind leaving this as it is, may be it
> would look better from code readability point of view if we wrap it.

Maybe I should just embrace the Pointer-Arith gcc extension:

  context = drv_context + (uintptr_t)context_offset;

Have to check first how prevalent it is already in the code.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[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