From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFA82606A322 for ; Thu, 3 Dec 2026 15:33:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hLxFtbn4 Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 18AF010E74D; Thu, 3 Dec 2026 15:33:37 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3D9D110E74D for ; Thu, 3 Dec 2026 15:33:31 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 4BB7B62B6A; Thu, 3 Dec 2026 15:33:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8F1D1F00899; Thu, 3 Dec 2026 15:33:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796312010; bh=y43lRn6UvK97bAB4mqZDqJdLoSG7E0mmCa49HzmFMLE=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=hLxFtbn4sD1Oza2CNEx+anxSZ+BXnGLAHvWOu71O7bFF2WoRM3H0tpHMefK01YuPU FlYK+Wvb67DXvqnhWVvH75/WAwDeZPQerhuCck6yCAtAz1ud6FrAsNeOBrh8rxvlld NouYKQcuXFvIJV710Atqk5ljsMFdZ2mQ5u+RDLBjSZR745Z39fUsSxhGpKrsXAwHAt /9o9zJ55X0869F+LCdjVJtDg7Rrhsk8vELFmgiORW1WYlVNcOTxJ+GCxr9E7l9Dm/f 5/iDAhcug9/y6rhxGnKTUWR0vn4x+6DeODEVpYdpmQIM8j3mY8Yeyy5mKztWcWHb4D SYU7m/LR5OoVQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] drm/panel: skip enable after a failed prepare To: "Qianhui Xu" , dri-devel@lists.freedesktop.org In-Reply-To: <20261203150951.261099-1-xiaqinghuan@mail.ustc.edu.cn> References: <20261203150951.261099-1-xiaqinghuan@mail.ustc.edu.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 15:33:29 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "dri-devel" X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: 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 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) > =20 > mutex_lock(&panel->follower_lock); > =20 > + panel->prepare_failed =3D false; > if (panel->funcs && panel->funcs->prepare) { > ret =3D panel->funcs->prepare(panel); > - if (ret < 0) > + if (ret < 0) { > + panel->prepare_failed =3D true; > goto exit; > + } > } > panel->prepared =3D true; > =20 > @@ -627,6 +630,16 @@ void drm_panel_unprepare(struct drm_panel *panel) > if (!panel) > return; > =20 > + /* > + * 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 =3D false; > + return; > + } > + > /* > * If you are seeing the warning below it likely means one of two thing= s: > * - 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; > =20 > + 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 =3D false panel->funcs->prepare() /* sleeps */ drm_panel_enable() if (panel->prepare_failed) /* false */ mutex_lock(&panel->follower_lock) /* prepare() returns < 0 */ panel->prepare_failed =3D true mutex_unlock(&panel->follower_lock) panel->funcs->enable() <-- unprepared panel->enabled =3D 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; > =20 > + /* 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 thing= s: > * - 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203150951.2610= 99-1-xiaqinghuan@mail.ustc.edu.cn?part=3D1