On Fri, Feb 07, 2025 at 03:32:00PM -0800, Dan Williams wrote: > > +#define fwctl_alloc_device(parent, ops, drv_struct, member) \ > > + ({ \ > > + static_assert(__same_type(struct fwctl_device, \ > > + ((drv_struct *)NULL)->member)); \ > > + static_assert(offsetof(drv_struct, member) == 0); \ > > + (drv_struct *)_fwctl_alloc_device(parent, ops, \ > > + sizeof(drv_struct)); \ > > + }) > > I have already suggested someone else copy this approach to context > allocation. What do you think of generalizing this in > include/linux/container_of.h as: I also have several places doing that too in iommufd and I think we have a variation in rdma as well. Let me suggest we go around after the fact and propose a consolidation patch. I think it will be easier to understand like that? > #define container_alloc(core_struct, drv_struct, member, alloc_fn, ...) \ > ({ \ > static_assert(__same_type(core_struct, \ > ((drv_struct *)NULL)->member)); \ > static_assert(offsetof(drv_struct, member) == 0); \ > (drv_struct *)(alloc_fn)(sizeof(drv_struct), __VA_ARGS__); \ > }) It makes sense to me Jason