[PATCH v4 01/14] iommufd/viommu: Introduce IOMMUFD_OBJ_VDEVICE and its related struct

Jason Gunthorpe jgg at nvidia.com
Fri Oct 25 06:20:54 PDT 2024


On Fri, Oct 25, 2024 at 06:53:01PM +1100, Alexey Kardashevskiy wrote:
> > +#define iommufd_vdevice_alloc(ictx, drv_struct, member)                        \
> > +	({                                                                     \
> > +		static_assert(                                                 \
> > +			__same_type(struct iommufd_vdevice,                    \
> > +				    ((struct drv_struct *)NULL)->member));     \
> > +		static_assert(offsetof(struct drv_struct, member.obj) == 0);   \
> > +		container_of(_iommufd_object_alloc(ictx,                       \
> > +						   sizeof(struct drv_struct),  \
> > +						   IOMMUFD_OBJ_VDEVICE),       \
> > +			     struct drv_struct, member.obj);                   \
> > +	})
> >   #endif
> 
> A nit: it hurts eyes to read:
> 
> mock_vdev = iommufd_vdevice_alloc(viommu->ictx, mock_vdevice, core);
> 
> vs.
> 
> mock_vdev = iommufd_vdevice_alloc(viommu->ictx, struct mock_vdevice, core);
> 
> as for the former I go searching for a "mock_vdevice" variable and for the
> latter it is clear it is 1) a macro 2) which does some type checking.
> 
> also, it makes it impossible to pass things like typeof(..) or a type from
> typedef. Thanks,

Makes sense to me

And the container_of() should not be used in these macros, the point
was to avoid it to make the PTR_ERR behavior cleraer. Just put a force
type cast

Jason



More information about the linux-arm-kernel mailing list