[PATCH v2 01/16] drm/panel: get/put panel reference in drm_panel_add/remove()

Anusha Srivatsa posted 16 patches 3 months, 3 weeks ago
[PATCH v2 01/16] drm/panel: get/put panel reference in drm_panel_add/remove()
Posted by Anusha Srivatsa 3 months, 3 weeks ago
Take the panel reference and put it back as required.
drm_panel_add() and drm_panel_remove() add a panel to
the global registry and removes a panel respectively.
Use get() and put() helpers to keep up with refcounting.

Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Signed-off-by: Anusha Srivatsa <asrivats@redhat.com>
---
 drivers/gpu/drm/drm_panel.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c
index 805b4151ccefd8ec0107951162c3b71446102ffb..ced6b08923b2150ebda6e1d9001517103895def1 100644
--- a/drivers/gpu/drm/drm_panel.c
+++ b/drivers/gpu/drm/drm_panel.c
@@ -80,6 +80,7 @@ EXPORT_SYMBOL(drm_panel_init);
  */
 void drm_panel_add(struct drm_panel *panel)
 {
+	drm_panel_get(panel);
 	mutex_lock(&panel_lock);
 	list_add_tail(&panel->list, &panel_list);
 	mutex_unlock(&panel_lock);
@@ -97,6 +98,7 @@ void drm_panel_remove(struct drm_panel *panel)
 	mutex_lock(&panel_lock);
 	list_del_init(&panel->list);
 	mutex_unlock(&panel_lock);
+	drm_panel_put(panel);
 }
 EXPORT_SYMBOL(drm_panel_remove);
 

-- 
2.48.1
Re: [PATCH v2 01/16] drm/panel: get/put panel reference in drm_panel_add/remove()
Posted by Luca Ceresoli 3 months, 2 weeks ago
Hello Anusha,

On Thu, 19 Jun 2025 14:15:53 -0500
Anusha Srivatsa <asrivats@redhat.com> wrote:

> Take the panel reference and put it back as required.
> drm_panel_add() and drm_panel_remove() add a panel to
> the global registry and removes a panel respectively.
> Use get() and put() helpers to keep up with refcounting.
> 
> Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
> Signed-off-by: Anusha Srivatsa <asrivats@redhat.com>

This patch is good.

I'd just point out that this must be applied only after all drivers
have been converted to the the _alloc API, otherwise with the following
sequence:

  panel = devm_kzalloc();
  drm_panel_init(panel);
  drm_panel_add(panel);
  ...
  drm_panel_remove(panel); <-----

at the drm_panel_remove() you'd have a warning:

  refcount_t: addition on 0; use-after-free.

So, if all panel drivers are converted:
Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com>

-- 
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Re: [PATCH v2 01/16] drm/panel: get/put panel reference in drm_panel_add/remove()
Posted by Maxime Ripard 3 months, 2 weeks ago
On Fri, Jun 20, 2025 at 10:33:53AM +0200, Luca Ceresoli wrote:
> Hello Anusha,
> 
> On Thu, 19 Jun 2025 14:15:53 -0500
> Anusha Srivatsa <asrivats@redhat.com> wrote:
> 
> > Take the panel reference and put it back as required.
> > drm_panel_add() and drm_panel_remove() add a panel to
> > the global registry and removes a panel respectively.
> > Use get() and put() helpers to keep up with refcounting.
> > 
> > Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
> > Signed-off-by: Anusha Srivatsa <asrivats@redhat.com>
> 
> This patch is good.
> 
> I'd just point out that this must be applied only after all drivers
> have been converted to the the _alloc API, otherwise with the following
> sequence:
> 
>   panel = devm_kzalloc();
>   drm_panel_init(panel);
>   drm_panel_add(panel);
>   ...
>   drm_panel_remove(panel); <-----
> 
> at the drm_panel_remove() you'd have a warning:
> 
>   refcount_t: addition on 0; use-after-free.
> 
> So, if all panel drivers are converted:

Not all panels are yet:
$ rg -l drm_panel_init -- drivers/gpu/drm/panel/ | wc -l
20

Maxime