Re: [PATCH rdma-next] RDMA: Provide safe ib_alloc_device() function

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

 



On Mon, Jan 28, 2019 at 07:01:41AM -0800, Bart Van Assche wrote:
> On 1/28/19 6:14 AM, Leon Romanovsky wrote:
> > -struct ib_device *ib_alloc_device(size_t size);
> > +void *_ib_alloc_device(size_t size);
> > +#define ib_alloc_device(drv_struct, member)                                    \
> > +	(BUILD_BUG_ON_ZERO(offsetof(struct drv_struct, member)) +              \
> > +	 BUILD_BUG_ON_ZERO(!__builtin_types_compatible_p(                      \
> > +		 typeof(((struct drv_struct *)NULL)->member),                  \
> > +		 struct ib_device)) +                                          \
> > +	 _ib_alloc_device(sizeof(struct drv_struct)))
> > +
>
> Hi Leon,
>
> Have you considered to use a comma expression and BUILD_BUG_ON() instead
> of adding the BUILD_BUG_ON_ZERO() results to the _ib_alloc_device()
> return value? I think that would result in slightly easier to read code
> and also in code that reflects the intent better.

I wanted to make sure that macro is used as assignment and returns
value, in such case it should be art of expression, hence in success
it is evaluated to 0.

I will very happy to receive code snippet for the same with BUILD_BUG_ON().

Thanks

>
> Thanks,
>
> Bart.

Attachment: signature.asc
Description: PGP signature


[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