From nobody Thu Apr 2 06:33:14 2026 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 BEDE9353EEC for ; Wed, 11 Feb 2026 21:40:08 +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=1770846011; cv=none; b=nlaQbKoANiHtlBoQ0w5UURpLPZTdWK5XfFejOg1AlZAi7K6LFfUpNZVbER2XrRQ5ahBlmYDfm+LXmeJi2ykk2Td+VxAhIbwrE7rVnEDUph0iYSTTprIDFGR8E4qgJaMVlQUrPO0QQYpEaWcQnRRpYhTphka/L/aIkS1HkNeCSn4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770846011; c=relaxed/simple; bh=0uwStfqWXamljtwZF4cHlK/oGasM1AvoMjnMzhL2ogY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WbvkIxpyhvq21awPT8awqNsOSy8ym/v8GjXdSYC/nf+L7B8G+2squRdOqd7s7J/kuU6Ucd/1ucjUr0jlRx7kZr60fAAEXlR+j10fBf6N5aMTrd+anju0phvq41GV3stkbf/2JZq8PkA6hOwgue/+2hbZ4biYibjb/LvPBNn3pKE= 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=JQvfHHcL; 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="JQvfHHcL" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id F2C2DC23D8A; Wed, 11 Feb 2026 21:40:15 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 12C0C606B1; Wed, 11 Feb 2026 21:40:07 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id EF8CC11949531; Wed, 11 Feb 2026 22:40:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1770846006; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=KHjTKyUMnae6tYGvVXBopaGafWE5D2GEW7x/Ab5dymQ=; b=JQvfHHcLEbWPtH3bGqB+yuadTQv9OG6OEvQoebbz4fBa0oJIf0ySze3+RY7PU80FD+vPfh GERCKCgxvWujtOrmA+fBCp/xgEWwta+sTz8D1p+do8EESWsd5pwPFRjAAOvz0mVmgbG/tC dp+xWdtUAI++2KEAOBtJzsYCHAUVp/LZwTawtoMoF1pGB00Oew6FmyhFZThnmLe2y09iJM JtOgaicmfZ+xrzDMLJ6GfeZq+dzxfceKff4fLtOVsBXepzxPq4ipnCnwAzJRpY4uzA7Inq 3+akA5riNpHSTkujwaiIgQThOZJAZ08/2s7ZhLF/yasKLnZO0N5F3HBuLcWZKw== From: Luca Ceresoli Date: Wed, 11 Feb 2026 22:39:49 +0100 Subject: [PATCH v6] drm/bridge: imx8qxp-pixel-link: get/put the next bridge 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: <20260211-drm-bridge-alloc-getput-drm_of_find_bridge-v6-1-651ddfd13bdb@bootlin.com> References: <20260211-drm-bridge-alloc-getput-drm_of_find_bridge-v6-0-651ddfd13bdb@bootlin.com> In-Reply-To: <20260211-drm-bridge-alloc-getput-drm_of_find_bridge-v6-0-651ddfd13bdb@bootlin.com> To: Liu Ying , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam Cc: Hui Pu , Ian Ray , Thomas Petazzoni , dri-devel@lists.freedesktop.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Luca Ceresoli X-Mailer: b4 0.15-dev-5464f X-Last-TLS-Session-Version: TLSv1.3 This driver obtains a bridge pointer from of_drm_find_bridge() in the probe function and stores it until driver removal. of_drm_find_bridge() is deprecated, so move to of_drm_find_and_get_bridge() for the bridge to be refcounted and use bridge->next_bridge to put the reference on deallocation. To keep the code as simple and reliable as possible remove the intermediate next_bridge and selected_bridge variables. Get/put operations on the remaining pointer is pl->bridge.next_bridge, which is tied to the struct imx8qxp_pixel_link lifetime, are: - get reference when assigned (by of_drm_find_and_get_bridge()) - put reference before reassignment if reassignment happens - put reference when the struct imx8qxp_pixel_link embedding the struct drm_bridge is destroyed (struct drm_bridge::next_bridge) Signed-off-by: Luca Ceresoli Acked-by: Liu Ying --- Changes in v6: - rewrite as suggested by Liu, removing the next_bridge pointer too and splitting the comment for maximum clarity - adapt commit message accordingly Changes in v5: - rewrite commit message after Liu's review to clarify the per-pointer get/put idea - split the if()s involved in selcting the bridge - remove intermediate selected_bridge pointer - removed Maxime's R-by, patch changed --- drivers/gpu/drm/bridge/imx/imx8qxp-pixel-link.c | 27 ++++++++++++---------= ---- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/bridge/imx/imx8qxp-pixel-link.c b/drivers/gpu/= drm/bridge/imx/imx8qxp-pixel-link.c index 91e4f4d55469..055b94d75eb6 100644 --- a/drivers/gpu/drm/bridge/imx/imx8qxp-pixel-link.c +++ b/drivers/gpu/drm/bridge/imx/imx8qxp-pixel-link.c @@ -23,7 +23,6 @@ =20 struct imx8qxp_pixel_link { struct drm_bridge bridge; - struct drm_bridge *next_bridge; struct device *dev; struct imx_sc_ipc *ipc_handle; u8 stream_id; @@ -140,7 +139,7 @@ static int imx8qxp_pixel_link_bridge_attach(struct drm_= bridge *bridge, } =20 return drm_bridge_attach(encoder, - pl->next_bridge, bridge, + pl->bridge.next_bridge, bridge, DRM_BRIDGE_ATTACH_NO_CONNECTOR); } =20 @@ -260,7 +259,6 @@ static int imx8qxp_pixel_link_find_next_bridge(struct i= mx8qxp_pixel_link *pl) { struct device_node *np =3D pl->dev->of_node; struct device_node *port; - struct drm_bridge *selected_bridge =3D NULL; u32 port_id; bool found_port =3D false; int reg; @@ -297,20 +295,21 @@ static int imx8qxp_pixel_link_find_next_bridge(struct= imx8qxp_pixel_link *pl) continue; } =20 - struct drm_bridge *next_bridge =3D of_drm_find_bridge(remote); - if (!next_bridge) - return -EPROBE_DEFER; - - /* - * Select the next bridge with companion PXL2DPI if - * present, otherwise default to the first bridge - */ - if (!selected_bridge || of_property_present(remote, "fsl,companion-pxl2d= pi")) - selected_bridge =3D next_bridge; + if (!pl->bridge.next_bridge) { + /* Select the first bridge by default... */ + pl->bridge.next_bridge =3D of_drm_find_and_get_bridge(remote); + if (!pl->bridge.next_bridge) + return -EPROBE_DEFER; + } else if (of_property_present(remote, "fsl,companion-pxl2dpi")) { + /* ... but prefer the companion PXL2DPI if present */ + drm_bridge_put(pl->bridge.next_bridge); + pl->bridge.next_bridge =3D of_drm_find_and_get_bridge(remote); + if (!pl->bridge.next_bridge) + return -EPROBE_DEFER; + } } =20 pl->mst_addr =3D port_id - 1; - pl->next_bridge =3D selected_bridge; =20 return 0; } --=20 2.52.0