From nobody Fri Dec 19 07:23:42 2025 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 096D931076D for ; Tue, 16 Dec 2025 18:01:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765908075; cv=none; b=gzr29gui/gJN1yd+BiNhfm6Mz08fmmVxlToVD7rg9k4TfD6pUm6h4I9Ik+hvTaC+ZyKFi5NAMPwR4Hs44NiNrbdC8256/9+M7Ol3KIJmincW5o9+qs9JjwI6rXMIvq311fJmiHRNv7fbo3mYcksc3gB4cuGCBKECZpkcyV9xyqE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765908075; c=relaxed/simple; bh=m5tCxOOQ5tmmSECH+iWR0MOz3DCJp/OH8KTzg1ovye0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hNLqmN57SQhdOwniHq6G7DoPOJyuscdb2UIVLghQdds2CHMwNDuanxmH7/HIab/188Y4TF3JbEYrwnFfjbMq9rpKPN98eGo6ofAgBpTnBrser11bfEo5lpVIxgdcHlSBOC7ZsuWMOe6t50ZoPLkreYRyOclOf2vY4jvb5Kx+m+8= 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=zc8GPsNZ; arc=none smtp.client-ip=185.246.85.4 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="zc8GPsNZ" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 7E0D74E41C36; Tue, 16 Dec 2025 18:01:12 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 42AD86071C; Tue, 16 Dec 2025 18:01:12 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 5EF25119A980E; Tue, 16 Dec 2025 19:01:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1765908070; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=rV1fjGxz59GFvzUULQooHruBRdYG3t1TVlD4LjvuTEk=; b=zc8GPsNZdo6fKnJmjXGh1kNhxRSx4Z9fSvDhy+xCe3z3BXENrcn4y7td35arslthDWCXzY LgUURCo19Vb5J6lm6/FmixeL049Xcq19LBDq7eZPcEMQLhfT+fpHAnufcaTi7qdhm6d++0 Q7krYwH7UFrbW5eEYD2KD1Lg2dmpdk+B0jQWAA0rhP8p+cZuOJIZ1IBEu7/BaNjAYXtvs3 SGkFaF4SGuoNS1EYB027PBS/Gb6JdCXqglf2DGqZOIi2F9X3jJQQtO4KzrDihitiW23N+I dgS6dmi5eoGzJOIXJQYu4EeFMmVz6yEbqbztBXKHe+tFdTpEKMNx/AmTdbfhrg== From: Luca Ceresoli Date: Tue, 16 Dec 2025 18:58:55 +0100 Subject: [PATCH v3 22/22] 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: <20251216-drm-bridge-alloc-getput-drm_of_find_bridge-v3-22-b5165fab8058@bootlin.com> References: <20251216-drm-bridge-alloc-getput-drm_of_find_bridge-v3-0-b5165fab8058@bootlin.com> In-Reply-To: <20251216-drm-bridge-alloc-getput-drm_of_find_bridge-v3-0-b5165fab8058@bootlin.com> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Jonathan Corbet , Alexey Brodkin , Phong LE , Liu Ying , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Kevin Hilman , Jerome Brunet , Martin Blumenstingl Cc: Hui Pu , Thomas Petazzoni , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org, Luca Ceresoli X-Mailer: b4 0.14.3 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. 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. This needs to be handled in various steps: * the bridge returned of_drm_get_bridge() is stored in the local temporary variable next_bridge whose scope is the for loop, so a cleanup action is enough * the value of next_bridge is copied into selected_bridge, potentially more than once, so a cleanup action at function scope plus a drm_bridge_put() in case of reassignment are enough * on successful return selected_bridge is stored in bridge->next_bridge, which ensures it is put when the bridge is deallocated Signed-off-by: Luca Ceresoli Reviewed-by: Maxime Ripard --- drivers/gpu/drm/bridge/imx/imx8qxp-pixel-link.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 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..b3050310a7f0 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,7 @@ 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; + struct drm_bridge *selected_bridge __free(drm_bridge_put) =3D NULL; u32 port_id; bool found_port =3D false; int reg; @@ -297,7 +296,8 @@ static int imx8qxp_pixel_link_find_next_bridge(struct i= mx8qxp_pixel_link *pl) continue; } =20 - struct drm_bridge *next_bridge =3D of_drm_find_bridge(remote); + struct drm_bridge *next_bridge __free(drm_bridge_put) =3D + of_drm_find_and_get_bridge(remote); if (!next_bridge) return -EPROBE_DEFER; =20 @@ -305,12 +305,14 @@ static int imx8qxp_pixel_link_find_next_bridge(struct= imx8qxp_pixel_link *pl) * 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 (!selected_bridge || of_property_present(remote, "fsl,companion-pxl2d= pi")) { + drm_bridge_put(selected_bridge); + selected_bridge =3D drm_bridge_get(next_bridge); + } } =20 pl->mst_addr =3D port_id - 1; - pl->next_bridge =3D selected_bridge; + pl->bridge.next_bridge =3D drm_bridge_get(selected_bridge); =20 return 0; } --=20 2.52.0