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 F2AFB10F9956 for ; Wed, 8 Apr 2026 16:02:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2BB0710E6A4; Wed, 8 Apr 2026 16:02:35 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="p1IDLQyG"; dkim-atps=neutral Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4E7D210E68D for ; Wed, 8 Apr 2026 16:02:33 +0000 (UTC) Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 6A9044E42967; Wed, 8 Apr 2026 16:02:31 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 29CF1603CB; Wed, 8 Apr 2026 16:02:31 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 1CEB210450178; Wed, 8 Apr 2026 18:02:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1775664147; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:content-language:in-reply-to:references; bh=KJRbJxNKCfc6JH7hozu9S72k8eerKMo5kB3arXaP38k=; b=p1IDLQyGfxO3wv2RgcPaWJq/raZE/sGDX1nRN6TPvRJ5+VX9BwWkm5q8XbM5gUxXkgWoin amDVHzyeh+alDZTY24NhTLHCxmNqIgvnA6kvxl+eiPpm7TmlaZMTNMwS8bJQ0aFGGSO+eM xuA7FYrLhqmHd1jY8gD+ddLzfWrp3GDPSJ5yVC1peK7oo9UZgDQ8AXSs/jF1DFujJ5WZs7 b/rd2+1eIYzwVuo1BO09GPTWhrs1dMftmzZcL7cY4V3ClsUz50ceEv0Tz5suVMCiNr2Pzk k2+v5J/Ygm+9/Et4NZP4muyPj7kl1UbY3uYCn9pPkW5uWKU9jqgd1acNn+EPKA== Message-ID: <4cd29943-a8d0-4706-b0c5-01d6b33863e4@bootlin.com> Date: Wed, 8 Apr 2026 18:03:01 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 3/4] drm: rcar-du: encoder: convert to of_drm_find_and_get_bridge() To: Luca Ceresoli , 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 References: <20260402-drm-bridge-alloc-getput-drm_of_find_bridge-4-v4-0-421781c8c061@bootlin.com> <20260402-drm-bridge-alloc-getput-drm_of_find_bridge-4-v4-3-421781c8c061@bootlin.com> From: Louis Chauvet Content-Language: en-US In-Reply-To: <20260402-drm-bridge-alloc-getput-drm_of_find_bridge-4-v4-3-421781c8c061@bootlin.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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" On 4/2/26 18:27, Luca Ceresoli wrote: > 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. > > We need to handle the two cases: when a panel_bridge is added and when it > isn't. So: > > * in the 'else' case a panel_bridge is not added and bridge is found: use > of_drm_find_and_get_bridge() to get a reference to the found bridge > * in the 'then' case a panel_bridge is found using a devm function which > already takes a refcount and will put it on removal, but we need to take > another so the following code in this function always get exactly one > reference that it needs to put > > In order to put the reference, add the needed drm_bridge_put() calls in the > existing cleanup function. > > Signed-off-by: Luca Ceresoli > > --- > > Changes in v4: > - fixed conflict after commit 3bce3fdd1ff2 ("drm: rcar-du: Don't leak > device_link to CMM") > - Use ARRAY_SIZE() instead of define > - Unsigned variable for never-negative variable > - Added comment to clarify the additional drm_bridge_get() in the > panel_bridge case > - Coding style (C comments, line wrap at 80) > --- > drivers/gpu/drm/renesas/rcar-du/rcar_du_encoder.c | 35 +++++++++++++++++++---- > drivers/gpu/drm/renesas/rcar-du/rcar_du_encoder.h | 1 + > drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c | 2 ++ > 3 files changed, 32 insertions(+), 6 deletions(-) > > diff --git a/drivers/gpu/drm/renesas/rcar-du/rcar_du_encoder.c b/drivers/gpu/drm/renesas/rcar-du/rcar_du_encoder.c > index 7ecec7b04a8d..0ae06edf3066 100644 > --- a/drivers/gpu/drm/renesas/rcar-du/rcar_du_encoder.c > +++ b/drivers/gpu/drm/renesas/rcar-du/rcar_du_encoder.c > @@ -51,7 +51,7 @@ int rcar_du_encoder_init(struct rcar_du_device *rcdu, > { > struct rcar_du_encoder *renc; > struct drm_connector *connector; > - struct drm_bridge *bridge; > + struct drm_bridge *bridge __free(drm_bridge_put) = NULL; > int ret; > > /* > @@ -69,20 +69,33 @@ int rcar_du_encoder_init(struct rcar_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); > + if (IS_ERR(bridge)) { > + /* Inhibit the cleanup action on an ERR_PTR */ > + ret = PTR_ERR(bridge); > + bridge = NULL; > + return ret; Same as before, can you use no_free_ptr? With or without this modification: Reviewed-by: Louis Chauvet > + } > + > + /* > + * 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; > > if (output == RCAR_DU_OUTPUT_LVDS0 || > output == RCAR_DU_OUTPUT_LVDS1) > - rcdu->lvds[output - RCAR_DU_OUTPUT_LVDS0] = bridge; > + rcdu->lvds[output - RCAR_DU_OUTPUT_LVDS0] = > + drm_bridge_get(bridge); > > if (output == RCAR_DU_OUTPUT_DSI0 || > output == RCAR_DU_OUTPUT_DSI1) > - rcdu->dsi[output - RCAR_DU_OUTPUT_DSI0] = bridge; > + rcdu->dsi[output - RCAR_DU_OUTPUT_DSI0] = > + drm_bridge_get(bridge); > } > > /* > @@ -135,3 +148,13 @@ int rcar_du_encoder_init(struct rcar_du_device *rcdu, > > return drm_connector_attach_encoder(connector, &renc->base); > } > + > +void rcar_du_encoder_cleanup(struct rcar_du_device *rcdu) > +{ > + unsigned int i; > + > + for (i = 0; i < ARRAY_SIZE(rcdu->lvds); i++) > + drm_bridge_put(rcdu->lvds[i]); > + for (i = 0; i < ARRAY_SIZE(rcdu->dsi); i++) > + drm_bridge_put(rcdu->dsi[i]); > +} > diff --git a/drivers/gpu/drm/renesas/rcar-du/rcar_du_encoder.h b/drivers/gpu/drm/renesas/rcar-du/rcar_du_encoder.h > index e5ec8fbb3979..b2b5e93f30f8 100644 > --- a/drivers/gpu/drm/renesas/rcar-du/rcar_du_encoder.h > +++ b/drivers/gpu/drm/renesas/rcar-du/rcar_du_encoder.h > @@ -25,5 +25,6 @@ struct rcar_du_encoder { > int rcar_du_encoder_init(struct rcar_du_device *rcdu, > enum rcar_du_output output, > struct device_node *enc_node); > +void rcar_du_encoder_cleanup(struct rcar_du_device *rcdu); > > #endif /* __RCAR_DU_ENCODER_H__ */ > diff --git a/drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c b/drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c > index b2d0e4651e35..1119c84e5fe9 100644 > --- a/drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c > +++ b/drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c > @@ -832,6 +832,8 @@ static void rcar_du_modeset_cleanup(struct drm_device *dev, void *res) > > put_device(cmm->dev); > } > + > + rcar_du_encoder_cleanup(rcdu); > } > > int rcar_du_modeset_init(struct rcar_du_device *rcdu) >