From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jason Gunthorpe Subject: Re: [PATCH 1/8] verbs: Always allocate a verbs_context Date: Thu, 11 Jan 2018 10:54:22 -0700 Message-ID: <20180111175422.GG30208@mellanox.com> References: <20180108212632.5183-1-jgg@ziepe.ca> <20180108212632.5183-2-jgg@ziepe.ca> <20180110173427.GE4776@mellanox.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: Sender: linux-rdma-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Devesh Sharma Cc: linux-rdma , Benjamin Drung , Doug Ledford , Yishai Hadas , Steve Wise , Mike Marciniszyn , Dennis Dalessandro , Lijun Ou , "Wei Hu(Xavier)" , Tatyana Nikolova , Vladimir Sokolovsky , Ram Amrani , Ariel Elior , Moni Shoua , Adit Ranadive , Leon Romanovsky , Nicolas Morey-Chaisemartin , Alexey Brodkin , Bar List-Id: linux-rdma@vger.kernel.org On Thu, Jan 11, 2018 at 11:14:33PM +0530, Devesh Sharma wrote: > On Wed, Jan 10, 2018 at 11:04 PM, Jason Gunthorpe 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-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html