Re: [PATCH v6 1/9] drm/managed: implement managed versions of kzalloc_obj/objs()

John Harrison <[email protected]>
Newsgroups org.kernel.vger.linux-renesas-soc,org.freedesktop.lists.amd-gfx,org.freedesktop.lists.dri-devel,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
On 6/12/26 11:30, Dmitry Baryshkov wrote:
> The kzalloc_obj() and kzalloc_objs() functions proven to be useful and
> widely used for the reset of the kernel. Implement a drm_device-managed
> versions of those macros to mix the nice interface with the automatic
> freeing of the pointers.
>
> Note: the original macros accept optional GFP_foo arguments. They are
> skipped for now, making all allocations use GFP_KERNEL. If necessary,
> support for overriding the GFP type can be introduced later.
>
> Signed-off-by: Dmitry Baryshkov <[email protected]>
> ---
>   include/drm/drm_managed.h | 22 ++++++++++++++++++++++
>   1 file changed, 22 insertions(+)
>
> diff --git a/include/drm/drm_managed.h b/include/drm/drm_managed.h
> index 72d0d68be226..79049bec277d 100644
> --- a/include/drm/drm_managed.h
> +++ b/include/drm/drm_managed.h
> @@ -105,6 +105,28 @@ static inline void *drmm_kcalloc(struct drm_device *dev,
>   	return drmm_kmalloc_array(dev, n, size, flags | __GFP_ZERO);
>   }
>   
> +/**
> + * drmm_kzalloc_objs - &drm_device-managed kzalloc_objs()
> + * @dev: DRM device
> + * @p: Variable or type to allocate an array of
> + * @count: How many elements in the array
> + *
> + * Returns: newly allocated pointer to the zeroed array of @P on success, or
There is a mix of p and P going on here. With this made more consistent:
Reviewed-by: John Harrison <[email protected]>

> + * NULL on failure.
> + */
> +#define drmm_kzalloc_objs(dev, p, count) \
> +	drmm_kcalloc(dev, count, sizeof(typeof(p)), GFP_KERNEL)
> +
> +/**
> + * drmm_kzalloc_obj - &drm_device-managed kzalloc_obj()
> + * @dev: DRM device
> + * @p: Variable or type to allocate
> + *
> + * Returns: newly allocated pointer to a @p on success, or NULL on failure.
> + */
> +#define drmm_kzalloc_obj(dev, P) \
> +	drmm_kzalloc_objs(dev, P, 1)
> +
>   char *drmm_kstrdup(struct drm_device *dev, const char *s, gfp_t gfp);
>   
>   void drmm_kfree(struct drm_device *dev, void *data);
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.