All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/panel: skip enable after a failed prepare
@ 2026-12-03 15:09 Qianhui Xu
  2026-12-03 15:33 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Qianhui Xu @ 2026-12-03 15:09 UTC (permalink / raw)
  To: Neil Armstrong, Jessica Zhang, dri-devel
  Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
	Simona Vetter, linux-kernel

drm_panel_prepare() cannot report a failure to its caller, so a panel
whose prepare callback failed is left unprepared while the bridge enable
chain still calls drm_panel_enable(). The core already knows the panel
was not prepared, since panel->prepared stays false, but that is
indistinguishable from a panel that never had a prepare callback.

Record the failure in drm_panel_prepare() and skip the enable callback
while it is set. unprepare() clears it, as the panel callbacks and
followers were never run, and disable() returns early for the same
reason. A later prepare() starts from a clean state, so a retry can
recover.

Signed-off-by: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>
---
Prepared with AI assistance (pi coding agent); reviewed and edited by me.

 drivers/gpu/drm/drm_panel.c | 24 +++++++++++++++++++++++-
 include/drm/drm_panel.h     |  8 ++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c
index 26d9378..0f22d45 100644
--- a/drivers/gpu/drm/drm_panel.c
+++ b/drivers/gpu/drm/drm_panel.c
@@ -588,10 +588,13 @@ void drm_panel_prepare(struct drm_panel *panel)
 
 	mutex_lock(&panel->follower_lock);
 
+	panel->prepare_failed = false;
 	if (panel->funcs && panel->funcs->prepare) {
 		ret = panel->funcs->prepare(panel);
-		if (ret < 0)
+		if (ret < 0) {
+			panel->prepare_failed = true;
 			goto exit;
+		}
 	}
 	panel->prepared = true;
 
@@ -627,6 +630,16 @@ void drm_panel_unprepare(struct drm_panel *panel)
 	if (!panel)
 		return;
 
+	/*
+	 * A failed prepare() left the panel unprepared. Drop the failure state
+	 * so that a later prepare() starts from a clean slate; the panel
+	 * callbacks and followers were never run.
+	 */
+	if (panel->prepare_failed) {
+		panel->prepare_failed = false;
+		return;
+	}
+
 	/*
 	 * If you are seeing the warning below it likely means one of two things:
 	 * - Your panel driver incorrectly calls drm_panel_unprepare() in its
@@ -683,6 +696,11 @@ void drm_panel_enable(struct drm_panel *panel)
 	if (!panel)
 		return;
 
+	if (panel->prepare_failed) {
+		dev_warn(panel->dev, "Skipping enable of panel that failed to prepare\n");
+		return;
+	}
+
 	if (panel->enabled) {
 		dev_warn(panel->dev, "Skipping enable of already enabled panel\n");
 		return;
@@ -733,6 +751,10 @@ void drm_panel_disable(struct drm_panel *panel)
 	if (!panel)
 		return;
 
+	/* The panel was never enabled after the failed prepare(). */
+	if (panel->prepare_failed)
+		return;
+
 	/*
 	 * If you are seeing the warning below it likely means one of two things:
 	 * - Your panel driver incorrectly calls drm_panel_disable() in its
diff --git a/include/drm/drm_panel.h b/include/drm/drm_panel.h
index d9059a9..60bcc3f 100644
--- a/include/drm/drm_panel.h
+++ b/include/drm/drm_panel.h
@@ -280,6 +280,14 @@ struct drm_panel {
 	 * If true then the panel has been enabled.
 	 */
 	bool enabled;
+
+	/**
+	 * @prepare_failed:
+	 *
+	 * If true then the last call to prepare() failed. The panel is not
+	 * prepared, and enable() will be skipped until prepare() succeeds.
+	 */
+	bool prepare_failed;
 };
 
 void *__devm_drm_panel_alloc(struct device *dev, size_t size, size_t offset,
-- 
2.53.0


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

* Re: [PATCH] drm/panel: skip enable after a failed prepare
  2026-12-03 15:09 [PATCH] drm/panel: skip enable after a failed prepare Qianhui Xu
@ 2026-12-03 15:33 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-03 15:33 UTC (permalink / raw)
  To: Qianhui Xu, dri-devel

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] drm/panel: drm_panel_disable() skips disable when
  prepare_failed is set
- [Medium] drm/panel: unlocked access and TOCTOU race on prepare_failed
- [Low] drm/panel: inaccurate commit rationale and incomplete
  prepare_failed doc
--

commit 9b6097fec1511c03195183722a065919a1cf9422
Author: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>

drm/panel: skip enable after a failed prepare

This commit tracks a failed drm_panel_prepare() in a new prepare_failed
flag so that drm_panel_enable() skips enabling an unprepared panel, while
drm_panel_disable() and drm_panel_unprepare() return early without
warning.

> The core already knows the panel
> was not prepared, since panel->prepared stays false, but that is
> indistinguishable from a panel that never had a prepare callback.

[Severity: Low]
Is this rationale accurate?  In drm_panel_prepare(), panel->prepared is
set to true even when panel->funcs->prepare is NULL.  The reason
drm_panel_enable() cannot check !panel->prepared is that some callers
invoke drm_panel_enable() without ever calling drm_panel_prepare(), such
as sti_dvo_pre_enable() in drivers/gpu/drm/sti/sti_dvo.c.

Also, the kernel-doc for @prepare_failed in include/drm/drm_panel.h
states that enable() is skipped until prepare() succeeds, without
mentioning that drm_panel_unprepare() also clears prepare_failed.

> diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c
> index 26d9378563f5c..0f22d45ce675e 100644
> --- a/drivers/gpu/drm/drm_panel.c
> +++ b/drivers/gpu/drm/drm_panel.c
> @@ -588,10 +588,13 @@ void drm_panel_prepare(struct drm_panel *panel)
>  
>  	mutex_lock(&panel->follower_lock);
>  
> +	panel->prepare_failed = false;
>  	if (panel->funcs && panel->funcs->prepare) {
>  		ret = panel->funcs->prepare(panel);
> -		if (ret < 0)
> +		if (ret < 0) {
> +			panel->prepare_failed = true;
>  			goto exit;
> +		}
>  	}
>  	panel->prepared = true;
>  
> @@ -627,6 +630,16 @@ void drm_panel_unprepare(struct drm_panel *panel)
>  	if (!panel)
>  		return;
>  
> +	/*
> +	 * A failed prepare() left the panel unprepared. Drop the failure state
> +	 * so that a later prepare() starts from a clean slate; the panel
> +	 * callbacks and followers were never run.
> +	 */
> +	if (panel->prepare_failed) {
> +		panel->prepare_failed = false;
> +		return;
> +	}
> +
>  	/*
>  	 * If you are seeing the warning below it likely means one of two things:
>  	 * - Your panel driver incorrectly calls drm_panel_unprepare() in its
> @@ -683,6 +696,11 @@ void drm_panel_enable(struct drm_panel *panel)
>  	if (!panel)
>  		return;
>  
> +	if (panel->prepare_failed) {
> +		dev_warn(panel->dev, "Skipping enable of panel that failed to prepare\n");
> +		return;
> +	}
> +
>  	if (panel->enabled) {
>  		dev_warn(panel->dev, "Skipping enable of already enabled panel\n");
>  		return;

[Severity: Medium]
Can concurrent callers race on panel->prepare_failed because it is checked
outside panel->follower_lock?

In drivers/gpu/drm/bridge/analogix/analogix-anx6345.c, a nonblocking
atomic commit runs anx6345_bridge_enable() -> drm_panel_enable() without
modeset locks or anx6345->lock, while anx6345_get_modes() can concurrently
call anx6345_poweron() -> drm_panel_prepare():

CPU0                                CPU1
drm_panel_prepare()
  mutex_lock(&panel->follower_lock)
  panel->prepare_failed = false
  panel->funcs->prepare() /* sleeps */
                                    drm_panel_enable()
                                      if (panel->prepare_failed) /* false */
                                      mutex_lock(&panel->follower_lock)
  /* prepare() returns < 0 */
  panel->prepare_failed = true
  mutex_unlock(&panel->follower_lock)
                                      panel->funcs->enable() <-- unprepared
                                      panel->enabled = true

Because drm_panel_enable() does not re-check panel->prepare_failed after
acquiring panel->follower_lock, it enables the unprepared panel, its
backlight, and followers while leaving both panel->prepare_failed and
panel->enabled true, so a later drm_panel_disable() returns early without
tearing them down.  drm_panel_unprepare() also reads and clears
panel->prepare_failed outside panel->follower_lock, creating a data race
with drm_panel_prepare().

Checking and updating panel->prepare_failed under panel->follower_lock in
all four helpers would avoid this.

> @@ -733,6 +751,10 @@ void drm_panel_disable(struct drm_panel *panel)
>  	if (!panel)
>  		return;
>  
> +	/* The panel was never enabled after the failed prepare(). */
> +	if (panel->prepare_failed)
> +		return;
> +
>  	/*
>  	 * If you are seeing the warning below it likely means one of two things:
>  	 * - Your panel driver incorrectly calls drm_panel_disable() in its

[Severity: Medium]
Can this early return skip disabling a panel that is already enabled?

In drivers/gpu/drm/bridge/analogix/analogix-anx6345.c,
anx6345_bridge_enable() calls drm_panel_enable() before anx6345_start() ->
anx6345_poweron() -> drm_panel_prepare().  If drm_panel_prepare() fails,
anx6345_bridge_disable() later calls drm_panel_disable() while both
panel->enabled and panel->prepare_failed are true.

Returning early before checking !panel->enabled skips
panel->funcs->disable(), backlight_disable(), and follower
panel_disabling() callbacks, leaving panel->enabled stuck at true so
subsequent drm_panel_enable() calls warn and skip re-enabling the panel.
Checking !panel->enabled first and using panel->prepare_failed only to
suppress the warning in that branch would keep enabled panels working.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203150951.261099-1-xiaqinghuan@mail.ustc.edu.cn?part=1

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

end of thread, other threads:[~2026-12-03 15:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 15:09 [PATCH] drm/panel: skip enable after a failed prepare Qianhui Xu
2026-12-03 15:33 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.