All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Qianhui Xu" <xiaqinghuan@mail.ustc.edu.cn>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2] drm/panel: skip enable after a failed prepare
Date: Fri, 04 Dec 2026 01:25:51 +0000	[thread overview]
Message-ID: <sashiko-outbox-248887@kernel.org> (raw)
In-Reply-To: <20261204011210.2494057-1-xiaqinghuan@mail.ustc.edu.cn>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/panel: unlocked prepared/enabled checks race with
  prepare_failed
--

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

drm/panel: skip enable after a failed prepare

This commit adds a prepare_failed flag to struct drm_panel so that
drm_panel_enable() skips enabling a panel whose prepare() callback failed,
and takes follower_lock before checking panel state in drm_panel_unprepare()
and drm_panel_disable().

> diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c
> index 26d9378563f5c..71ff02c84c74e 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,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;
>  	}

[Severity: Medium]
Can concurrent drm_panel_prepare() calls leave both panel->prepared and
panel->prepare_failed set, causing drm_panel_unprepare() to skip unpreparing
the panel?

drm_panel_prepare() still checks panel->prepared before taking
panel->follower_lock and does not recheck it under the lock.  Callers are not
always externally serialized: in analogix-anx6345, anx6345_get_modes() calls
anx6345_poweron() -> drm_panel_prepare() under anx6345->lock and
mode_config.mutex, while anx6345_bridge_enable() calls anx6345_start() ->
anx6345_poweron() -> drm_panel_prepare() without either lock.

CPU0                                CPU1
drm_panel_prepare()                 drm_panel_prepare()
  if (panel->prepared) -> false       if (panel->prepared) -> false
  mutex_lock(&panel->follower_lock)
  funcs->prepare() -> 0
  panel->prepared = true
  mutex_unlock(&panel->follower_lock)
                                      mutex_lock(&panel->follower_lock)
                                      funcs->prepare() -> -EIO
                                      panel->prepare_failed = true
                                      mutex_unlock(&panel->follower_lock)
drm_panel_unprepare()
  if (panel->prepare_failed)  <-- skips unprepare while prepared is true

Because drm_panel_unprepare() checks panel->prepare_failed before
!panel->prepared, it clears prepare_failed and returns early without
notifying panel_unpreparing followers, calling funcs->unprepare(), or
clearing panel->prepared, leaking the panel's prepared state and resources.

drm_panel_enable() has the same unlocked panel->enabled check outside
follower_lock, leaving a data race with drm_panel_disable() and allowing
concurrent callers to double-enable the panel, backlight, and followers.  The
kernel-doc comment for follower_lock in include/drm/drm_panel.h also still
states that it only locks the followers list.

Moving mutex_lock(&panel->follower_lock) above the prepared and enabled
checks in drm_panel_prepare() and drm_panel_enable(), and checking
panel->prepare_failed inside the !panel->prepared branch in
drm_panel_unprepare() (matching drm_panel_disable()), would close both the
race and the state-machine mismatch.

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

      reply	other threads:[~2026-12-04  1:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  1:12 [PATCH v2] drm/panel: skip enable after a failed prepare Qianhui Xu
2026-12-04  1:25 ` 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-248887@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.