On Thu, May 08, 2025 at 08:02:31PM -0700, Nicolin Chen wrote: > +#define iommufd_hw_queue_alloc(viommu, drv_struct, member) > \ > + ({ \ > + drv_struct *ret; \ > + \ > + static_assert(__same_type(struct iommufd_viommu, *viommu)); \ > + static_assert(__same_type(struct iommufd_hw_queue, \ > + ((drv_struct *)NULL)->member)); \ > + static_assert(offsetof(drv_struct, member.obj) == 0); \ > + ret = (drv_struct *)_iommufd_object_alloc( \ > + viommu->ictx, sizeof(drv_struct), \ > + IOMMUFD_OBJ_HW_QUEUE); \ > + if (!IS_ERR(ret)) { \ > + ret->member.viommu = viommu; \ > + ret->member.ictx = viommu->ictx; \ > + } \ > + ret; \ > + })
This should just call __iommufd_object_alloc(viommu->ictx, ret, IOMMUFD_OBJ_HW_QUEUE member.obj) And all the casting and asserts should be in that macro, move it to this header > /* Helper for IOMMU driver to destroy structures created by allocators above > */ > #define iommufd_struct_destroy(drv_struct, member) > \ > ({ \ This is abort not destroy, the names should be consistent. But looking more at the series I think it will be better to do the little rework I suggested and not give this function to the driver in the first place. Jason