From: sashiko-bot@kernel.org
To: "Qianhui Xu" <xiaqinghuan@mail.ustc.edu.cn>,
dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/panel: skip enable after a failed prepare
Date: Thu, 03 Dec 2026 15:33:29 +0000 [thread overview]
Message-ID: <sashiko-outbox-248117@kernel.org> (raw)
In-Reply-To: <20261203150951.261099-1-xiaqinghuan@mail.ustc.edu.cn>
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
prev parent reply other threads:[~2026-12-03 15:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 15:09 [PATCH] drm/panel: skip enable after a failed prepare Qianhui Xu
2026-12-03 15:33 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-248117@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=xiaqinghuan@mail.ustc.edu.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.