From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 91F0DEA3C4E for ; Thu, 9 Apr 2026 13:23:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E428B10E7F0; Thu, 9 Apr 2026 13:23:47 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="kTfepyfD"; dkim-atps=neutral Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) by gabe.freedesktop.org (Postfix) with ESMTPS id DA91810E7F0 for ; Thu, 9 Apr 2026 13:23:46 +0000 (UTC) Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 64ECC1A31F2; Thu, 9 Apr 2026 13:23:45 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 3AF6760410; Thu, 9 Apr 2026 13:23:45 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id EB9C7104500C4; Thu, 9 Apr 2026 15:23:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1775741024; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=DDz3EPGSkC5c3+H2Kn58ldMSafMOB1Yx1zAfhDY5z48=; b=kTfepyfDzj0WT9+sKKJwlzVVZStANXiiSaJmsvBveUDx0YrOvcwI5w7N9uhPvtVak3C37M JT+yYkt6wtLxic05OG86a8JEggoF+0HfFPaxaYihEf1DqHtpeJP5Esk9dDVcEI3nm+xm0V +lBvyHxoVy7OpR2qBFWUKteU3v4AxP1j13OqWNkUX6rquTWSqhyHzLqQg0RVCFiKuCr7Q9 oIbWkR1lVtg2Kerhv4oorDqwYx39dTRlqsgWaMEYowo9tRGdFYbzVlbAf84/pbY1Xr1nDO XVjl6mQitVqb3ZY4K4z9fD/rc058jPKMOPV+sWVYZM0/dplp06iDcTZCDEb9xA== From: Luca Ceresoli Date: Thu, 09 Apr 2026 15:23:28 +0200 Subject: [PATCH v5 1/2] drm: renesas: rz-du: rzg2l_du_encoder: convert to of_drm_find_and_get_bridge() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260409-drm-bridge-alloc-getput-drm_of_find_bridge-4-v5-1-d7381c07788a@bootlin.com> References: <20260409-drm-bridge-alloc-getput-drm_of_find_bridge-4-v5-0-d7381c07788a@bootlin.com> In-Reply-To: <20260409-drm-bridge-alloc-getput-drm_of_find_bridge-4-v5-0-d7381c07788a@bootlin.com> To: Biju Das , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Anitha Chrisanthus , Linus Walleij , Laurent Pinchart , Tomi Valkeinen , Kieran Bingham , Geert Uytterhoeven , Magnus Damm , Tomi Valkeinen Cc: Hui Pu , Ian Ray , Thomas Petazzoni , dri-devel@lists.freedesktop.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Luca Ceresoli , Louis Chauvet X-Mailer: b4 0.15.1 X-Last-TLS-Session-Version: TLSv1.3 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" of_drm_find_bridge() is deprecated. Move to its replacement of_drm_find_and_get_bridge() which gets a bridge reference, and ensure it is put when done. This is made somewhat simpler by the fact that 'bridge' is a local variable. However we need to handle both branches of the main if(). In the 'else' case, just switch to of_drm_find_and_get_bridge() to ensure the bridge is not freed while in use in the function tail (drm_bridge_attach() mainly). In the 'then' case, devm_drm_panel_bridge_add_typed() already increments the refcount using devres which ties the bridge allocation lifetime to the device lifetime, so we would not need to do anything. However to have the same behaviour in both branches take an additional reference here, so that the bridge needs to be put whichever branch is taken without more complicated logic. Reviewed-by: Biju Das Tested-by: Biju Das Reviewed-by: Linus Walleij Reviewed-by: Laurent Pinchart Reviewed-by: Louis Chauvet Signed-off-by: Luca Ceresoli --- Changes in v5: - simplify error bailout using no_free_ptr Changes in v4: - Added comment to clarify the additional drm_bridge_get() in the panel_bridge case (keeping the R-by and T-by tags as it's just a comment) --- drivers/gpu/drm/renesas/rz-du/rzg2l_du_encoder.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/renesas/rz-du/rzg2l_du_encoder.c b/drivers/gpu/drm/renesas/rz-du/rzg2l_du_encoder.c index 5e6dd16705e6..d53068733c66 100644 --- a/drivers/gpu/drm/renesas/rz-du/rzg2l_du_encoder.c +++ b/drivers/gpu/drm/renesas/rz-du/rzg2l_du_encoder.c @@ -67,7 +67,7 @@ int rzg2l_du_encoder_init(struct rzg2l_du_device *rcdu, { struct rzg2l_du_encoder *renc; struct drm_connector *connector; - struct drm_bridge *bridge; + struct drm_bridge *bridge __free(drm_bridge_put) = NULL; int ret; /* @@ -84,9 +84,16 @@ int rzg2l_du_encoder_init(struct rzg2l_du_device *rcdu, bridge = devm_drm_panel_bridge_add_typed(rcdu->dev, panel, DRM_MODE_CONNECTOR_DPI); if (IS_ERR(bridge)) - return PTR_ERR(bridge); + return PTR_ERR(no_free_ptr(bridge)); + + /* + * The reference taken by devm_drm_panel_bridge_add_typed() is + * released automatically. Take a second one for the __free() + * when this function will return. + */ + drm_bridge_get(bridge); } else { - bridge = of_drm_find_bridge(enc_node); + bridge = of_drm_find_and_get_bridge(enc_node); if (!bridge) return -EPROBE_DEFER; } -- 2.53.0