Re: [PATCH v4 12/23] iommufd/driver: Add iommufd_hw_queue_depend/undepend() helpers

Jason Gunthorpe
2025-05-15T16:13:02Z

On Thu, May 08, 2025 at 08:02:33PM -0700, Nicolin Chen wrote:

> +/*
> + * Helpers for IOMMU driver to build/destroy a dependency between two sibling
> + * structures created by one of the allocators above
> + */
> +#define iommufd_hw_queue_depend(dependent, depended, member) \
> + ({ \
> + static_assert(__same_type(struct iommufd_hw_queue, \
> + dependent->member)); \
> + static_assert(offsetof(typeof(*dependent), member.obj) == 0); \
> + static_assert(__same_type(struct iommufd_hw_queue, \
> + depended->member)); \
> + static_assert(offsetof(typeof(*depended), member.obj) == 0); \
> + _iommufd_object_depend(&dependent->member.obj, \
> + &depended->member.obj); \
> + })

This doesn't need the offsetof == 0 checks, it isn't an allocator. And
you want to check that the two structs have the same type:

static_assert(__same_type(struct iommufd_hw_queue, dependent->member));
static_assert(__same_type(typeof(*dependent), *dependend));

Jason