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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 2FAD0CF34C8 for ; Wed, 19 Nov 2025 15:05:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:References:From:To:Cc: Subject:Message-Id:Date:Mime-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=bvO8lFnaDxFnijqJm8lCE5OcJpSbI29OkLVi2RY4ZB0=; b=fP7fvtG+J/d1t/ hqHlOkVtErEKlt8aklzIg+1JjhpSaVcM4C4envzATjFw8yIrg7/5qtjqu3NLNyZAAauXArLKH1HsY 2gn25b511jVFqtA7kbRgX8Cfuq+gvm3PqOPZdf2XY4F/I17MiZbplBag9JmHXvHF6jukc4nThpyHZ 47r3yJRlhiwRf0RkjVh5mEBJkFGVUym0nBhmIxA/369y886i1c4ckxMiCCmHZQ5GucT5m70GdkwVV a7AsKtpbKFY47wuoHeXV4YuPV8a86nVKhvpHMjtQ4xSXHGk1JWi/G9pD/D5HMdGhwUKAlTbsGTvsY NBDXVbVlRp8FfLklpiYA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vLjkN-00000003SbJ-2bT7; Wed, 19 Nov 2025 15:05:27 +0000 Received: from smtpout-04.galae.net ([185.171.202.116]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vLjkK-00000003SYa-2CH5 for linux-amlogic@lists.infradead.org; Wed, 19 Nov 2025 15:05:26 +0000 Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 303A6C1118A; Wed, 19 Nov 2025 15:05:00 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 5ACA160699; Wed, 19 Nov 2025 15:05:22 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id A4C1410371A6A; Wed, 19 Nov 2025 16:05:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763564719; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=F7QYsJvko3OwXBuoQqrMWaiZs2Tw0yizTy6p7UD4rac=; b=sOEuzAxEZWuQ3AUbFtEgUlf2cgtfZWFBSyylVKX8jZsilf0pjAXIS/1dUfJVSv11XNTJuI C0XUe2nv5ky9Mn/3MfiFXv1n/0JLHDWaG0itUKmX2QaboBI96GBbNFKrjGYu+8SCdV0DBT LKR1vwDMaGbq7Lkp1S3fONcv4bUe4hEcHgUnX1la5CRLY0y1raK/rkHodxNqKDleqAdoSi l3OyZqJGWvRsUtgJI97b41UaOy9g8IytQezx8tiRjlP6MmIfs6wVpTYa4Exv8EJrrMgsKh R21w3WrZaNqF/CfQUtZMsjnN4+WrwU+pd84dsLKf7gEcDQXt1HEx0nqD76YBcA== Mime-Version: 1.0 Date: Wed, 19 Nov 2025 16:05:05 +0100 Message-Id: Subject: Re: [PATCH 06/26] drm/bridge: add devm_drm_of_find_bridge Cc: "Hui Pu" , "Thomas Petazzoni" , , , , , , , , , To: "Louis Chauvet" , "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" , "Adrien Grassein" , "Laurent Pinchart" , "Tomi Valkeinen" , "Kieran Bingham" , "Geert Uytterhoeven" , "Magnus Damm" , "Kevin Hilman" , "Jerome Brunet" , "Martin Blumenstingl" , "Chun-Kuang Hu" , "Philipp Zabel" , "Matthias Brugger" , "AngeloGioacchino Del Regno" , "Anitha Chrisanthus" , "Edmund Dea" , "Inki Dae" , "Seung-Woo Kim" , "Kyungmin Park" , "Krzysztof Kozlowski" , "Alim Akhtar" From: "Luca Ceresoli" X-Mailer: aerc 0.20.1 References: <20251119-drm-bridge-alloc-getput-drm_of_find_bridge-v1-0-0db98a7fe474@bootlin.com> <20251119-drm-bridge-alloc-getput-drm_of_find_bridge-v1-6-0db98a7fe474@bootlin.com> <0858117f-9397-4045-9b7d-490ad24926cb@bootlin.com> In-Reply-To: <0858117f-9397-4045-9b7d-490ad24926cb@bootlin.com> X-Last-TLS-Session-Version: TLSv1.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251119_070524_857213_2571195F X-CRM114-Status: GOOD ( 25.45 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org Hi Louis, On Wed Nov 19, 2025 at 3:33 PM CET, Louis Chauvet wrote: > > > On 11/19/25 13:05, Luca Ceresoli wrote: >> Several drivers (about 20) follow the same pattern: >> >> 1. get a pointer to a bridge (typically the next bridge in the chain) by >> calling of_drm_find_bridge() >> 2. store the returned pointer in the private driver data, keep it until >> driver .remove >> 3. dereference the pointer at attach time and possibly at other times >> >> of_drm_find_bridge() is now deprecated because it does not increment the >> refcount and should be replaced with drm_of_find_bridge() + >> drm_bridge_put(). >> >> However some of those drivers have a complex code flow and adding a >> drm_bridge_put() call in all the appropriate locations is error-prone, >> leads to ugly and more complex code, and can lead to errors over time with >> code flow changes. >> >> To handle all those drivers in a straightforward way, add a devm variant of >> drm_of_find_bridge() that adds a devm action to invoke drm_bridge_put() >> when the said driver is removed. This allows all those drivers to put the >> reference automatically and safely with a one line change: >> >> - priv->next_bridge = of_drm_find_bridge(remote_np); >> + priv->next_bridge = devm_drm_of_find_bridge(dev, remote_np); >> >> Signed-off-by: Luca Ceresoli >> --- >> drivers/gpu/drm/drm_bridge.c | 30 ++++++++++++++++++++++++++++++ >> include/drm/drm_bridge.h | 5 +++++ >> 2 files changed, 35 insertions(+) >> >> diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c >> index 09ad825f9cb8..c7baafbe5695 100644 >> --- a/drivers/gpu/drm/drm_bridge.c >> +++ b/drivers/gpu/drm/drm_bridge.c >> @@ -1446,6 +1446,36 @@ struct drm_bridge *drm_of_find_bridge(struct device_node *np) >> } >> EXPORT_SYMBOL(drm_of_find_bridge); >> >> +/** >> + * devm_drm_of_find_bridge - find the bridge corresponding to the device >> + * node in the global bridge list and add a devm >> + * action to put it >> + * >> + * @dev: device requesting the bridge >> + * @np: device node >> + * >> + * On success the returned bridge refcount is incremented, and a devm >> + * action is added to call drm_bridge_put() when @dev is removed. So the >> + * caller does not have to put the returned bridge explicitly. >> + * >> + * RETURNS: >> + * drm_bridge control struct on success, NULL on failure > > I am not sure for the "NULL on failure", you return ERR_PTR(err), which > is probably not NULL but an error code. Indeed. Apologies for the mess in this series: it was adapted from an old one using a different approach, so I had to adapt lots of details, and missed a few along the way. :( About the value to return, maybe it's better to use the same semantics as drm_of_find_bridge(), i.e. NULL on error. I don't think a caller would have anything clever to do with an error return value other tan bailing out. And the only error path for devm_add_action_or_reset() is on a small allocation, so it basically cannot happen. >> +struct drm_bridge *devm_drm_of_find_bridge(struct device *dev, struct device_node *np) >> +{ >> + struct drm_bridge *bridge = drm_of_find_bridge(np); >> + >> + if (bridge) { >> + int err = devm_add_action_or_reset(dev, drm_bridge_put_void, bridge); >> + >> + if (err) >> + return ERR_PTR(err); >> + } So this would become: if (bridge) { if (devm_add_action_or_reset(dev, drm_bridge_put_void, bridge)) return NULL; } >> + >> + return bridge; >> +} Luca -- Luca Ceresoli, Bootlin Embedded Linux and Kernel engineering https://bootlin.com _______________________________________________ linux-amlogic mailing list linux-amlogic@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-amlogic