lkml.org 
[lkml]   [2024]   [May]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH RFCv1 03/14] iommufd: Prepare for viommu structures and functions
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'

Jason

\
 
 \ /
  Last update: 2024-05-27 18:25    [from the cache]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and my Meterkast|Read the blog