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 4642F606A322 for ; Fri, 4 Dec 2026 01:26:05 +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=DGdOBQTQ Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AC78710EBB8; Fri, 4 Dec 2026 01:25:59 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2F17E10E47C for ; Fri, 4 Dec 2026 01:25:53 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 2EDBB60F33; Fri, 4 Dec 2026 01:25:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6C761F000C2; Fri, 4 Dec 2026 01:25:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796347551; bh=w44D/F0okDm3ClGbAvQ86NdH+ZdDt/+1o2vd89lC27s=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=DGdOBQTQ4sWIXvLl3TvilpHc/PkAIblcn2Hsno8ibdTjjF7ZTcYnmgLPGadBwj8Yq u54Q/q08+36TICT/yk+4cLatp9G02Wbn1xAy2zS9KA5FzCo1DA+RsmK/2c7Yxn7a4c djaGc702wty9vEZfrjlbzVZ2xJKBJAT/Rpa0mj2meR8xSr8o7MaIJa7lrFCeqA9oQ3 2TfUwSwjGjevVlEM3+JcW6aSuz+azxBjY12u/wSKbLt3wBF9ooiA536DOaR6LS20OY 71h6mji8ZaPlwlgDl3DsTbe2c2Z7I97z+ugUbj7SCFL7ECfBOQETeynIQnQDQZmHeL 2seHKIFDSyqBg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] drm/panel: skip enable after a failed prepare To: "Qianhui Xu" Cc: dri-devel@lists.freedesktop.org In-Reply-To: <20261204011210.2494057-1-xiaqinghuan@mail.ustc.edu.cn> References: <20261204011210.2494057-1-xiaqinghuan@mail.ustc.edu.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 01:25:51 +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 1 potential issue to consider: - [Medium] drm/panel: unlocked prepared/enabled checks race with prepare_failed -- commit e6cd2e46fb366816df1f1e1a8842c2eb5b26a566 Author: Qianhui Xu 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) > =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,18 @@ void drm_panel_unprepare(struct drm_panel *panel) > if (!panel) > return; > =20 > + 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 =3D false; > + goto exit; > + } > + > /* > * 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 > @@ -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 n= ot 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 =3D true mutex_unlock(&panel->follower_lock) mutex_lock(&panel->follower_lock) funcs->prepare() -> -EIO panel->prepare_failed =3D 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. T= he 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204011210.2494= 057-1-xiaqinghuan@mail.ustc.edu.cn?part=3D1