From nobody Sat Apr 18 11:10:05 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 5028A3D3D0C for ; Thu, 9 Apr 2026 13:23:54 +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=1775741035; cv=none; b=Q13taZWYQcJzMZxI0DVm+Zybz8OABy/ZgWyh9V3CRTvtOd+ZejD6uDqQKM9k7MDtLG9N3ahG72s+EEymFSMgZFBNDlY18bfRzHiMP+VVpR3bcP2/atEbjo/MiMksv5sfCeu1GEeFcVVKPyfPuBKYK4lt7qVqO2PbQqDBdakzyIg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775741035; c=relaxed/simple; bh=qivQdL2d5ja/ofIgpoWR9LR2aJHZbHdMuurVGQJqOaU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gmqDWzMEsizMvy68rAH+FXkqfNFTTaLaRfGda0UvgmXusSdHwVOt/iDGcwshsxrfObAcBqrJfCmvSSSex0O2nm6RUx5DA6v/KaD8ehvdlNl/zp3OqkTZAgg0+uFDYS+09FhDi2yrh8SUIu88lFymd4aZl3KI/KRX9+EmgPOFoF0= 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=kTfepyfD; 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="kTfepyfD" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 8B45EC5C188; Thu, 9 Apr 2026 13:24:27 +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() 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: <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 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) =3D NULL; int ret; =20 /* @@ -84,9 +84,16 @@ int rzg2l_du_encoder_init(struct rzg2l_du_device *rcdu, bridge =3D 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 =3D of_drm_find_bridge(enc_node); + bridge =3D of_drm_find_and_get_bridge(enc_node); if (!bridge) return -EPROBE_DEFER; } --=20 2.53.0 From nobody Sat Apr 18 11:10:05 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (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 CDE6F26A1AC; Thu, 9 Apr 2026 13:23:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775741031; cv=none; b=JT9BgHlzsq3XimSqIiGq9y9/3CtJRAV6I0fMHtEBrowh4Lv5/XvDJcwltWScR/2Vx8zTcVSo/Pk9+Q0YiuQkp/sDW1Zu7dMe5jKnM3FFStuBNLNkE0GL5WzXZNxZdVfUj9vKfcjkZlaTGvTf7s0572fl1n1HQi246V49GlTJnx8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775741031; c=relaxed/simple; bh=6IY4R9XjIqQmjxiONSVAiY1vtNeCPXtooa3KEqLGJqc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qcHUwZ4Rlo/cGhgtUTdEJmXMIpRNuTzy6it07VO6SQn2APug2UQYtw044bJ3IG/Xfz72B6tizuW3/5p4zS0tOMyihJo/HoiQWaA6k+ALVQMFRxI4tL9rAPqxVUSj4SpxblJ7zeZHcoeBTtizJLiupdWPq2RvXxNC0z+p0rAJQrU= 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=g6xMpgjp; arc=none smtp.client-ip=185.246.84.56 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="g6xMpgjp" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 601011A3110; Thu, 9 Apr 2026 13:23:48 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 35DFA5FDEB; Thu, 9 Apr 2026 13:23:48 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 7EE4A104500CC; Thu, 9 Apr 2026 15:23:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1775741027; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=fVytxjV17xgSK10EcsYyGCsPOjuobSuyvtNitHNtoxY=; b=g6xMpgjp786lwmwHMvkneopo5MudqqKPEJnnZHvtLdVMLwzvvs4PJd3chB7LZcjUBoLK5T 8iE1/qaJjvuYrTIEsqoDTpRKpMTlawF+ao32uB9lrzeGSK55NsXajGSAd30QdMD/0oCI77 Hc8PSjP2Ne9Aj2BEipM9ajcbOE6CumJvBC6+uNfc70p1SX2ltmSEVV0HpUkPB2mVgaCbS3 zEPb2pJLPBNaRPmGsgvk1ThuiLFhzpsak0n6LZ4uh46c8dEVHZttB3dN01YYqS8eroRQQv e5P4MyjV/bMRU5a8X9QxfyGVFxvQtWnat1R8gEiUuGlhFHndq30kamosTqrSUg== From: Luca Ceresoli Date: Thu, 09 Apr 2026 15:23:29 +0200 Subject: [PATCH v5 2/2] drm: rcar-du: encoder: convert to of_drm_find_and_get_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: <20260409-drm-bridge-alloc-getput-drm_of_find_bridge-4-v5-2-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 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. 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: - 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 | 29 +++++++++++++++++++= ---- 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, 27 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/renesas/rcar-du/rcar_du_encoder.c b/drivers/gp= u/drm/renesas/rcar-du/rcar_du_encoder.c index 7ecec7b04a8d..32ea09d65d76 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) =3D NULL; int ret; =20 /* @@ -70,19 +70,28 @@ int rcar_du_encoder_init(struct rcar_du_device *rcdu, bridge =3D 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 =3D of_drm_find_bridge(enc_node); + bridge =3D of_drm_find_and_get_bridge(enc_node); if (!bridge) return -EPROBE_DEFER; =20 if (output =3D=3D RCAR_DU_OUTPUT_LVDS0 || output =3D=3D RCAR_DU_OUTPUT_LVDS1) - rcdu->lvds[output - RCAR_DU_OUTPUT_LVDS0] =3D bridge; + rcdu->lvds[output - RCAR_DU_OUTPUT_LVDS0] =3D + drm_bridge_get(bridge); =20 if (output =3D=3D RCAR_DU_OUTPUT_DSI0 || output =3D=3D RCAR_DU_OUTPUT_DSI1) - rcdu->dsi[output - RCAR_DU_OUTPUT_DSI0] =3D bridge; + rcdu->dsi[output - RCAR_DU_OUTPUT_DSI0] =3D + drm_bridge_get(bridge); } =20 /* @@ -135,3 +144,13 @@ int rcar_du_encoder_init(struct rcar_du_device *rcdu, =20 return drm_connector_attach_encoder(connector, &renc->base); } + +void rcar_du_encoder_cleanup(struct rcar_du_device *rcdu) +{ + unsigned int i; + + for (i =3D 0; i < ARRAY_SIZE(rcdu->lvds); i++) + drm_bridge_put(rcdu->lvds[i]); + for (i =3D 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/gp= u/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); =20 #endif /* __RCAR_DU_ENCODER_H__ */ diff --git a/drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c b/drivers/gpu/dr= m/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) =20 put_device(cmm->dev); } + + rcar_du_encoder_cleanup(rcdu); } =20 int rcar_du_modeset_init(struct rcar_du_device *rcdu) --=20 2.53.0