On Sun, May 12, 2024 at 10:42:12AM -0300, Jason Gunthorpe wrote: > On Fri, Apr 12, 2024 at 08:47:00PM -0700, Nicolin Chen wrote: > > > +static inline struct iommufd_object *___iommufd_object_alloc(size_t size) > > +{ > > + struct iommufd_object *obj; > > + > > + obj = kzalloc(size, GFP_KERNEL_ACCOUNT); > > + if (!obj) > > + return ERR_PTR(-ENOMEM); > > + > > + /* Starts out bias'd by 1 until it is removed from the xarray */ > > + refcount_set(&obj->shortterm_users, 1); > > + refcount_set(&obj->users, 1); > > + > > + /* > > + * The allocation of an obj->id needs an ictx, so it has to be done > > + * after this ___iommufd_object_alloc() callback. > > + */ > > + > > + return obj; > > +} > > It is probably cleaner to just make the existing allocation work with > a NULL ictx for this case? Then we can use the existing alloc > functions. > > > +#define viommu_struct_alloc(name) \ > > + struct iommufd_##name *_iommufd_##name##_alloc(size_t size) \ > > + { \ > > + struct iommufd_object *obj; \ > > + if (WARN_ON(size < sizeof(struct iommufd_##name))) \ > > + return NULL; \ > > Then here you'd just use the exisint container_of based flow with the > driver sub struct name passed as the 'obj' Yes. And then we can probably unwrap this macro too since it's no long that verbose to duplicate in viommu/vqueue allocators. Thanks Nicolin