mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/panel: novatek-nt36536: Fix panel double-remove on attach failure
@ 2026-07-24  4:17 David Carlier
  2026-07-25 11:17 ` Pengyu Luo
  2026-07-27  8:13 ` Neil Armstrong
  0 siblings, 2 replies; 3+ messages in thread
From: David Carlier @ 2026-07-24  4:17 UTC (permalink / raw)
  To: neil.armstrong, mitltlatltl
  Cc: jesszhan0024, maarten.lankhorst, mripard, tzimmermann, airlied,
	simona, dri-devel, linux-kernel, David Carlier

The DSI attach error path calls drm_panel_remove() by hand even though
the panel was registered with devm_drm_panel_add(), which already
arranges for drm_panel_remove() to run on driver detach. When
mipi_dsi_attach() fails the panel is therefore removed twice: once
directly and once again while devres unwinds.

drm_panel_add() takes a reference and drm_panel_remove() drops one, so
the extra removal releases the last reference early and frees the panel
container. The put registered by devm_drm_panel_alloc() then operates on
freed memory, resulting in a use-after-free and a reference-count
underflow when a DSI host rejects the requested configuration during
probe.

Drop the manual drm_panel_remove() and let the managed cleanup handle
it, matching the other dual-DSI panel drivers.

Fixes: 75a5dbd1f4f7 ("drm/panel: Add Novatek NT36536 panel driver")
Signed-off-by: David Carlier <devnexen@gmail.com>
---
 drivers/gpu/drm/panel/panel-novatek-nt36536.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/panel/panel-novatek-nt36536.c b/drivers/gpu/drm/panel/panel-novatek-nt36536.c
index 2a82b54880c3..8bd125650168 100644
--- a/drivers/gpu/drm/panel/panel-novatek-nt36536.c
+++ b/drivers/gpu/drm/panel/panel-novatek-nt36536.c
@@ -429,11 +429,9 @@ static int novatek_probe(struct mipi_dsi_device *dsi)
 		ctx->dsi[i]->mode_flags = desc->mode_flags;
 		ctx->dsi[i]->dsc = &ctx->dsc;
 		ret = devm_mipi_dsi_attach(dev, ctx->dsi[i]);
-		if (ret < 0) {
-			drm_panel_remove(&ctx->panel);
+		if (ret < 0)
 			return dev_err_probe(dev, ret,
 					     "Failed to attach to DSI host\n");
-		}
 	}
 
 	if (desc->has_dcs_backlight) {
-- 
2.53.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/panel: novatek-nt36536: Fix panel double-remove on attach failure
  2026-07-24  4:17 [PATCH] drm/panel: novatek-nt36536: Fix panel double-remove on attach failure David Carlier
@ 2026-07-25 11:17 ` Pengyu Luo
  2026-07-27  8:13 ` Neil Armstrong
  1 sibling, 0 replies; 3+ messages in thread
From: Pengyu Luo @ 2026-07-25 11:17 UTC (permalink / raw)
  To: David Carlier
  Cc: neil.armstrong, jesszhan0024, maarten.lankhorst, mripard,
	tzimmermann, airlied, simona, dri-devel, linux-kernel

On Fri, Jul 24, 2026 at 12:17 PM David Carlier <devnexen@gmail.com> wrote:
>
> The DSI attach error path calls drm_panel_remove() by hand even though
> the panel was registered with devm_drm_panel_add(), which already
> arranges for drm_panel_remove() to run on driver detach. When
> mipi_dsi_attach() fails the panel is therefore removed twice: once
> directly and once again while devres unwinds.
>
> drm_panel_add() takes a reference and drm_panel_remove() drops one, so
> the extra removal releases the last reference early and frees the panel
> container. The put registered by devm_drm_panel_alloc() then operates on
> freed memory, resulting in a use-after-free and a reference-count
> underflow when a DSI host rejects the requested configuration during
> probe.
>
> Drop the manual drm_panel_remove() and let the managed cleanup handle
> it, matching the other dual-DSI panel drivers.
>
> Fixes: 75a5dbd1f4f7 ("drm/panel: Add Novatek NT36536 panel driver")
> Signed-off-by: David Carlier <devnexen@gmail.com>
> ---

Thanks!

Reviewed-by: Pengyu Luo <mitltlatltl@gmail.com>

>  drivers/gpu/drm/panel/panel-novatek-nt36536.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/panel/panel-novatek-nt36536.c b/drivers/gpu/drm/panel/panel-novatek-nt36536.c
> index 2a82b54880c3..8bd125650168 100644
> --- a/drivers/gpu/drm/panel/panel-novatek-nt36536.c
> +++ b/drivers/gpu/drm/panel/panel-novatek-nt36536.c
> @@ -429,11 +429,9 @@ static int novatek_probe(struct mipi_dsi_device *dsi)
>                 ctx->dsi[i]->mode_flags = desc->mode_flags;
>                 ctx->dsi[i]->dsc = &ctx->dsc;
>                 ret = devm_mipi_dsi_attach(dev, ctx->dsi[i]);
> -               if (ret < 0) {
> -                       drm_panel_remove(&ctx->panel);
> +               if (ret < 0)
>                         return dev_err_probe(dev, ret,
>                                              "Failed to attach to DSI host\n");
> -               }
>         }
>
>         if (desc->has_dcs_backlight) {
> --
> 2.53.0
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/panel: novatek-nt36536: Fix panel double-remove on attach failure
  2026-07-24  4:17 [PATCH] drm/panel: novatek-nt36536: Fix panel double-remove on attach failure David Carlier
  2026-07-25 11:17 ` Pengyu Luo
@ 2026-07-27  8:13 ` Neil Armstrong
  1 sibling, 0 replies; 3+ messages in thread
From: Neil Armstrong @ 2026-07-27  8:13 UTC (permalink / raw)
  To: mitltlatltl, David Carlier
  Cc: jesszhan0024, maarten.lankhorst, mripard, tzimmermann, airlied,
	simona, dri-devel, linux-kernel

Hi,

On Fri, 24 Jul 2026 05:17:46 +0100, David Carlier wrote:
> The DSI attach error path calls drm_panel_remove() by hand even though
> the panel was registered with devm_drm_panel_add(), which already
> arranges for drm_panel_remove() to run on driver detach. When
> mipi_dsi_attach() fails the panel is therefore removed twice: once
> directly and once again while devres unwinds.
> 
> drm_panel_add() takes a reference and drm_panel_remove() drops one, so
> the extra removal releases the last reference early and frees the panel
> container. The put registered by devm_drm_panel_alloc() then operates on
> freed memory, resulting in a use-after-free and a reference-count
> underflow when a DSI host rejects the requested configuration during
> probe.
> 
> [...]

Thanks, Applied to https://gitlab.freedesktop.org/drm/misc/kernel.git (drm-misc-next)

[1/1] drm/panel: novatek-nt36536: Fix panel double-remove on attach failure
      https://gitlab.freedesktop.org/drm/misc/kernel/-/commit/4085da1e6ad90ca7a227d8528de2c77042fabf8a

-- 
Neil


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-07-27  8:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-24  4:17 [PATCH] drm/panel: novatek-nt36536: Fix panel double-remove on attach failure David Carlier
2026-07-25 11:17 ` Pengyu Luo
2026-07-27  8:13 ` Neil Armstrong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome