Re: [PATCH v2] IB/uverbs: Add UVERBS_ATTR_FLAGS_IN to the specs language

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

 



On Wed, Jul 25, 2018 at 08:46:33AM -0600, Jason Gunthorpe wrote:
> On Wed, Jul 25, 2018 at 08:47:09AM +0300, Leon Romanovsky wrote:
> > On Tue, Jul 24, 2018 at 02:37:11PM -0600, Jason Gunthorpe wrote:
> > > This clearly indicates that the input is a bitwise combination of values
> > > in an enum, and identifies which enum contains the definition of the bits.
> > >
> > > Special accessors are provided that handle the mandatory validation of the
> > > allowed bits and enforce the correct type for bitwise flags.
> > >
> > > If we had introduced this at the start then the kabi would have uniformly
> > > used u64 data to pass flags, however today there is a mixture of u64 and
> > > u32 flags. All places are converted to accept both sizes and the accessor
> > > fixes it. This allows all existing flags to grow to u64 in future without
> > > any hassle.
> > >
> > > Finally all flags are, by definition, optional. If flags are not passed
> > > the accessor does not fail, but provides a value of zero.
> > >
> > > Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxxxx>
> >
> > ....
> >
> > > +#define UVERBS_ATTR_FLAGS_IN(_attr_id, _enum_type, ...)                        \
> > > +	UVERBS_ATTR_PTR_IN(                                                    \
> > > +		_attr_id,                                                      \
> > > +		UVERBS_ATTR_SIZE(sizeof(_enum_type) * 0 + sizeof(u32),         \
> >
> >                                                     ^^^^^
> > What did you mean by " * 0"?
>
> This is a meta-programming technique to confirm that _enum_type is a
> valid expression.
>
> Otherwise _enum_type is not used in the macro at all and could have a typo..
>
> Maybe it should be
>
>   sizeof(_enum_type *)*0
>
> which further requires enum_type to be a type expression..

I didn't check it, but think that BUILD_BUG_ON(!sizeof(_enum_type)) will
do the trick without "meta-programming technique".

Thanks

>
> Jason

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