<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Thu, Mar 27, 2025 at 11:58 AM Maxime Ripard <<a href="mailto:mripard@kernel.org">mripard@kernel.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Thu, Mar 27, 2025 at 10:55:39AM -0400, Anusha Srivatsa wrote:<br>
> Introduce reference counted allocations for panels to avoid<br>
> use-after-free. The patch adds the macro devm_drm_bridge_alloc()<br>
> to allocate a new refcounted panel. Followed the documentation for<br>
> drmm_encoder_alloc() and devm_drm_dev_alloc and other similar<br>
> implementations for this purpose.<br>
> <br>
> v2: Better documentation for connector_type field - follow drm_panel_init<br>
> documentation. (Luca)<br>
> - Clarify the refcount initialisation in comments.(Maxime)<br>
> - Correct the documentation of the return type (Maxime)<br>
> <br>
> Signed-off-by: Anusha Srivatsa <<a href="mailto:asrivats@redhat.com" target="_blank">asrivats@redhat.com</a>><br>
> ---<br>
> drivers/gpu/drm/drm_panel.c | 25 +++++++++++++++++++++++++<br>
> include/drm/drm_panel.h | 23 +++++++++++++++++++++++<br>
> 2 files changed, 48 insertions(+)<br>
> <br>
> diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c<br>
> index c627e42a7ce70459f50eb5095fffc806ca45dabf..bdeab5710ee324dc1742fbc77582250960556308 100644<br>
> --- a/drivers/gpu/drm/drm_panel.c<br>
> +++ b/drivers/gpu/drm/drm_panel.c<br>
> @@ -355,6 +355,31 @@ struct drm_panel *of_drm_find_panel(const struct device_node *np)<br>
> }<br>
> EXPORT_SYMBOL(of_drm_find_panel);<br>
> <br>
> +void *__devm_drm_panel_alloc(struct device *dev, size_t size, size_t offset,<br>
> + const struct drm_panel_funcs *funcs,<br>
> + int connector_type)<br>
> +{<br>
> + void *container;<br>
> + struct drm_panel *panel;<br>
> +<br>
> + if (!funcs) {<br>
> + dev_warn(dev, "Missing funcs pointer\n");<br>
> + return ERR_PTR(-EINVAL);<br>
> + }<br>
> +<br>
> + container = devm_kzalloc(dev, size, GFP_KERNEL);<br>
> + if (!container)<br>
> + return ERR_PTR(-ENOMEM);<br>
> +<br>
> + panel = container + offset;<br>
> + panel->funcs = funcs;<br>
> +<br>
> + drm_panel_init(panel, dev, funcs, connector_type);<br>
> +<br>
> + return container;<br>
> +}<br>
> +EXPORT_SYMBOL(__devm_drm_panel_alloc);<br>
> +<br>
> /**<br>
> * of_drm_get_panel_orientation - look up the orientation of the panel through<br>
> * the "rotation" binding from a device tree node<br>
> diff --git a/include/drm/drm_panel.h b/include/drm/drm_panel.h<br>
> index a9c042c8dea1a82ef979c7a68204e0b55483fc28..53251c6b11d78149ede3dad41ffa6a88f3c3c58b 100644<br>
> --- a/include/drm/drm_panel.h<br>
> +++ b/include/drm/drm_panel.h<br>
> @@ -28,6 +28,7 @@<br>
> #include <linux/errno.h><br>
> #include <linux/list.h><br>
> #include <linux/mutex.h><br>
> +#include <linux/kref.h><br>
> <br>
> struct backlight_device;<br>
> struct dentry;<br>
> @@ -268,6 +269,28 @@ struct drm_panel {<br>
> bool enabled;<br>
> };<br>
> <br>
> +void *__devm_drm_panel_alloc(struct device *dev, size_t size, size_t offset,<br>
> + const struct drm_panel_funcs *funcs,<br>
> + int connector_type);<br>
> +<br>
> +/**<br>
> + * devm_drm_panel_alloc - Allocate and initialize an refcounted panel<br>
> + * @dev: struct device of the panel device<br>
> + * @type: the type of the struct which contains struct &drm_panel<br>
> + * @member: the name of the &drm_panel within @type<br>
> + * @funcs: callbacks for this panel<br>
> + * @connector_type: the connector type (DRM_MODE_CONNECTOR_*) corresponding to<br>
> + * the panel interface<br>
> + * Returns:<br>
> + * Pointer to container structure embedding the panel, ERR_PTR on failure.<br>
> + * The reference count is initialised to 1 and is automatically given back<br>
> + * by devm action.<br>
<br>
Sorry, I noticed after the facts, but this can't be in the Returns<br>
section, it needs to be in the main one.<br>
<br></blockquote><div>Maxime, Not really following you. Are you suggesting this explanation needs to be in the helper documentation </div><div>instead of in returns?</div><div><br></div><div>Anusha</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Maxime<br>
</blockquote></div></div>