From nobody Wed Dec 17 19:16:26 2025 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0EDFA2EC0BF for ; Fri, 3 Oct 2025 10:39:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759487998; cv=none; b=Dg0yatAlyBVotGXP25Nh6JdpiLtcLR9FWkdjAwStE8tadURT7Le68rtM5oAxd3UNeItR9FQWum4Mu60LBN0xU0S8CqjXGfXxKPk6IwJ2JZWS+5ryhtX3Dj2Z3QYzRv5AqvnsHkeVYPzSY7uteVYfMIruveFoRP6chEaTesfslq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759487998; c=relaxed/simple; bh=VOr5eBoNc9FnNHnP9I1a7YeygagW6If0Sow2UvyqWHU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CiK78NoWz3bVCRVlUq1ltt2p3rbgt5LJBqjGOJdqKp9c9hy4QJzaZhASDU3h4onn+m2WTcniVlPC1qHbm0pKT1mRVDDV4blYn/UTMKr8oIJCbS+AJMPm8hP0gB6qPFtNNycoTHPNCiLq/A4IOSJ5t5EEnMQq/CgfSb8YPpibsSU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=wtYD1khi; arc=none smtp.client-ip=185.171.202.116 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="wtYD1khi" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 808D9C00D98; Fri, 3 Oct 2025 10:39:37 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 8103560683; Fri, 3 Oct 2025 10:39:55 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id E1134102F1C6C; Fri, 3 Oct 2025 12:39:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1759487994; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=tbt/7EiW1spKYTs5CQJj03xNV0I741bKU71RrfYpRZA=; b=wtYD1khie8pKkgE+AJBUeKyUOUNq8cQJOHgD94ksjKwHFbBS2F6nPLkC1LSz2dvNsFWhd3 QFHGsvUL5GYWCJnDlmRok6dqb53ovlMujxwrl/D0C5dAtDNqNRDWxdEVGtFQ2UgM6dBNct NnUet2rzjjqbF+TcJCtTafPA0wWkWM3qJMm7WBRtfNXrYXkp9EVU0mNSFS1egijheh1pfa 9ivubEtXhh3DxPhU/mea4OxAYFKE/+xhmStjUPP7XBEBTYAfrUkeVG69eaNw4rHs9rCmfH //qxhniDxsWvLoA1kwBfW9bicTeClWf+0SlpsqbVuf+VOC7/rBwWrK/nTMORVg== From: Luca Ceresoli Date: Fri, 03 Oct 2025 12:39:29 +0200 Subject: [PATCH v2 7/7] drm/bridge: prevent encoder chain changes in pre_enable/post_disable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251003-drm-bridge-alloc-encoder-chain-mutex-v2-7-78bf61580a06@bootlin.com> References: <20251003-drm-bridge-alloc-encoder-chain-mutex-v2-0-78bf61580a06@bootlin.com> In-Reply-To: <20251003-drm-bridge-alloc-encoder-chain-mutex-v2-0-78bf61580a06@bootlin.com> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec Cc: Hui Pu , Thomas Petazzoni , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Luca Ceresoli X-Mailer: b4 0.14.2 X-Last-TLS-Session-Version: TLSv1.3 Take the encoder chain mutex while iterating over the encoder chain in drm_atomic_bridge_chain_pre_enable() and drm_atomic_bridge_chain_post_disable() to ensure the lists won't change while being inspected. These functions have nested list_for_each_*() loops, which makes them complicated. list_for_each_entry_from() loops could be replaced by drm_for_each_bridge_in_chain_from(), but it would not work in a nested way in its current implementation. Besides, there is no "_reverse" variant of drm_for_each_bridge_in_chain_from(). Keep code simple and readable by explicitly locking around the outer loop. Thankfully there are no return points inside the loops, so the change is trivial and readable. Signed-off-by: Luca Ceresoli --- Changes in v2: - Improved commit message --- drivers/gpu/drm/drm_bridge.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c index 2a55ac5697e0b4faa21f01728bbe287a95cd99a6..840ea4ef4bb27ea035cda784f8e= c39cd768ed704 100644 --- a/drivers/gpu/drm/drm_bridge.c +++ b/drivers/gpu/drm/drm_bridge.c @@ -760,6 +760,7 @@ void drm_atomic_bridge_chain_post_disable(struct drm_br= idge *bridge, =20 encoder =3D bridge->encoder; =20 + drm_encoder_chain_lock(encoder); list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) { limit =3D NULL; =20 @@ -808,6 +809,7 @@ void drm_atomic_bridge_chain_post_disable(struct drm_br= idge *bridge, /* Jump all bridges that we have already post_disabled */ bridge =3D limit; } + drm_encoder_chain_unlock(encoder); } EXPORT_SYMBOL(drm_atomic_bridge_chain_post_disable); =20 @@ -854,6 +856,7 @@ void drm_atomic_bridge_chain_pre_enable(struct drm_brid= ge *bridge, =20 encoder =3D bridge->encoder; =20 + drm_encoder_chain_lock(encoder); list_for_each_entry_reverse(iter, &encoder->bridge_chain, chain_node) { if (iter->pre_enable_prev_first) { next =3D iter; @@ -896,6 +899,7 @@ void drm_atomic_bridge_chain_pre_enable(struct drm_brid= ge *bridge, if (iter =3D=3D bridge) break; } + drm_encoder_chain_unlock(encoder); } EXPORT_SYMBOL(drm_atomic_bridge_chain_pre_enable); =20 --=20 2.51.0