* [PATCH v3] drm/panel: skip enable after a failed prepare
@ 2026-12-04 4:03 Qianhui Xu
2026-12-04 4:19 ` sashiko-bot
0 siblings, 1 reply; 3+ messages in thread
From: Qianhui Xu @ 2026-12-04 4:03 UTC (permalink / raw)
To: Neil Armstrong, Jessica Zhang
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, dri-devel, 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(). enable() cannot rely on the
prepared flag for this, as some drivers call it without preparing first
(sti_dvo_pre_enable()), so record the failure separately.
Set prepare_failed when the callback fails and skip the enable callback,
its backlight and the followers while it is set. unprepare() clears it,
as none of them ran, and disable() only uses it to stay quiet about
disabling a panel that was never enabled: a panel that was enabled before
the failed prepare is still disabled.
All reads and writes of prepared, enabled and the flag happen with
follower_lock held, which all four helpers now take before looking at
the panel state. This keeps a concurrent prepare() from leaving the
panel both prepared and marked as failed, which would make unprepare()
skip the whole unprepare chain and leak the prepared state.
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 | 49 +++++++++++++++++++++++++++----------
include/drm/drm_panel.h | 8 ++++++
2 files changed, 44 insertions(+), 13 deletions(-)
diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c
index 26d937856..1e1d9e5ed 100644
--- a/drivers/gpu/drm/drm_panel.c
+++ b/drivers/gpu/drm/drm_panel.c
@@ -581,17 +581,20 @@ void drm_panel_prepare(struct drm_panel *panel)
if (!panel)
return;
+ mutex_lock(&panel->follower_lock);
+
if (panel->prepared) {
dev_warn(panel->dev, "Skipping prepare of already prepared panel\n");
- return;
+ goto exit;
}
- 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,18 @@ void drm_panel_unprepare(struct drm_panel *panel)
if (!panel)
return;
+ mutex_lock(&panel->follower_lock);
+
+ /*
+ * A failed prepare() returned before the panel callbacks and the
+ * followers ran, so there is nothing to undo here. Drop the failure
+ * so that the check below does not report it as a driver bug.
+ */
+ if (panel->prepare_failed) {
+ panel->prepare_failed = false;
+ goto exit;
+ }
+
/*
* If you are seeing the warning below it likely means one of two things:
* - Your panel driver incorrectly calls drm_panel_unprepare() in its
@@ -638,11 +653,9 @@ void drm_panel_unprepare(struct drm_panel *panel)
*/
if (!panel->prepared) {
dev_warn(panel->dev, "Skipping unprepare of already unprepared panel\n");
- return;
+ goto exit;
}
- mutex_lock(&panel->follower_lock);
-
list_for_each_entry(follower, &panel->followers, list) {
if (!follower->funcs->panel_unpreparing)
continue;
@@ -683,12 +696,17 @@ void drm_panel_enable(struct drm_panel *panel)
if (!panel)
return;
+ mutex_lock(&panel->follower_lock);
+
if (panel->enabled) {
dev_warn(panel->dev, "Skipping enable of already enabled panel\n");
- return;
+ goto exit;
}
- mutex_lock(&panel->follower_lock);
+ if (panel->prepare_failed) {
+ dev_warn(panel->dev, "Skipping enable of panel that failed to prepare\n");
+ goto exit;
+ }
if (panel->funcs && panel->funcs->enable) {
ret = panel->funcs->enable(panel);
@@ -733,6 +751,8 @@ void drm_panel_disable(struct drm_panel *panel)
if (!panel)
return;
+ mutex_lock(&panel->follower_lock);
+
/*
* If you are seeing the warning below it likely means one of two things:
* - Your panel driver incorrectly calls drm_panel_disable() in its
@@ -743,12 +763,15 @@ void drm_panel_disable(struct drm_panel *panel)
* figure out how to reverse the order of the shutdown() callbacks.
*/
if (!panel->enabled) {
- dev_warn(panel->dev, "Skipping disable of already disabled panel\n");
- return;
+ /*
+ * A failed prepare() is an expected reason for getting here,
+ * so only the warning is dropped.
+ */
+ if (!panel->prepare_failed)
+ dev_warn(panel->dev, "Skipping disable of already disabled panel\n");
+ goto exit;
}
- mutex_lock(&panel->follower_lock);
-
list_for_each_entry(follower, &panel->followers, list) {
if (!follower->funcs->panel_disabling)
continue;
diff --git a/include/drm/drm_panel.h b/include/drm/drm_panel.h
index d9059a960..f21845257 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:
+ *
+ * Set when the panel's prepare() callback failed. enable() is skipped
+ * while it is set. A later prepare() or unprepare() clears it.
+ */
+ 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] 3+ messages in thread
* Re: [PATCH v3] drm/panel: skip enable after a failed prepare
2026-12-04 4:03 [PATCH v3] drm/panel: skip enable after a failed prepare Qianhui Xu
@ 2026-12-04 4:19 ` sashiko-bot
2026-12-04 9:04 ` Qianhui Xu
0 siblings, 1 reply; 3+ messages in thread
From: sashiko-bot @ 2026-12-04 4:19 UTC (permalink / raw)
To: Qianhui Xu; +Cc: dri-devel
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] drm/panel: stale follower_lock doc and overly broad commit
locking claim
--
commit 176ae2399799a2aa4414b9123430d1e072bb7acb
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 drm_panel_enable() skips enabling the panel, and takes
follower_lock before reading or updating the panel state flags in the
four drm_panel helpers.
> All reads and writes of prepared, enabled and the flag happen with
> follower_lock held, which all four helpers now take before looking at
> the panel state.
[Severity: Low]
Should this claim be scoped to the drm_panel core helpers? Drivers
outside drm_panel.c (e.g. s6e8aa5x01_ams561ra01_update_status() in
panel-samsung-s6e8aa5x01-ams561ra01.c) still read panel.prepared or
panel.enabled without follower_lock.
Also, the kernel-doc for follower_lock in include/drm/drm_panel.h still
says only "Lock for followers list.", and prepared, enabled, and
prepare_failed do not mention it. Updating those comments avoids future
changes bypassing follower_lock when no followers are registered.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204040332.175830-1-xiaqinghuan@mail.ustc.edu.cn?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] drm/panel: skip enable after a failed prepare
2026-12-04 4:19 ` sashiko-bot
@ 2026-12-04 9:04 ` Qianhui Xu
0 siblings, 0 replies; 3+ messages in thread
From: Qianhui Xu @ 2026-12-04 9:04 UTC (permalink / raw)
To: Neil Armstrong, Jessica Zhang
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, dri-devel, linux-kernel
Hi,
disclosure first: I draft these mails with an AI assistant and edit them
myself; the content, the measurements and the decisions are mine.
Thanks for the review.
- [Low] "overly broad locking claim": correct, the claim should be scoped to
the four drm_panel helpers. Four panel drivers still read the flags without
follower_lock (panel-anapass-ana38407.c:228, panel-samsung-sofef00.c:179,
panel-synaptics-tddi.c:59, panel-samsung-s6e8aa5x01-ams561ra01.c:768, all in
the backlight ->update_status() path). The message should not claim more
than "the four drm_panel helpers".
- [Low] stale follower_lock doc: correct. include/drm/drm_panel.h still says
only "Lock for followers list." while prepared/enabled/prepare_failed are
now documented against that lock.
The [Medium] race reported on v2 is addressed in v3: the four helpers take
follower_lock before looking at the state, so a concurrent prepare can no
longer leave prepared && prepare_failed behind.
Would you prefer the two doc/wording fixes as a v4 respin of the single
patch, or should I keep them for a follow-up? I have not sent a v4.
Regards,
Qianhui
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-04 9:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 4:03 [PATCH v3] drm/panel: skip enable after a failed prepare Qianhui Xu
2026-12-04 4:19 ` sashiko-bot
2026-12-04 9:04 ` Qianhui Xu
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.