From patchwork Thu Feb 6 18:14:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 13963592 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 90600C0219B for ; Thu, 6 Feb 2025 19:01:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=nGVO+QbU0hs3mabM5lWL+R6oDUNoq4UxfAsW2GhkoGA=; b=HAzFJqUWjXF2PoCukEojsNPvlE t5TW6kv3QUOMj5b5Geax2u/HQ9rmylVAi5Hxz4cz5CilQTc3M8sae5Toq/rIuptRVKu6sJAPI1E0P hZ4brUx2+AyXKZIKLioGRJjHbAzfKEETvNxHfY65MCCXJ8SwIuCa1Ad5C2MuUSg3Z2b6CBePfq39j 4j3XbOhNq3kdBpRDQqjjeCI+pqOCGloIazn759uHOZa0OTua6V9bn+J+dSEXmqI9CPYveoIm9UKSf dBgOIkOjgxeXcTU9w7PSCeovzxFjHBwim8d++Bn+LSMFZ5uf0yox6RouRKBk0I/me19OTdQE8BJ1M 1OiPQ7Mw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tg77j-00000007HvS-1GgB; Thu, 06 Feb 2025 19:01:15 +0000 Received: from relay6-d.mail.gandi.net ([2001:4b98:dc4:8::226]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tg6PH-0000000783t-0uhs for linux-arm-kernel@lists.infradead.org; Thu, 06 Feb 2025 18:15:20 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 06C4344264; Thu, 6 Feb 2025 18:15:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1738865717; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nGVO+QbU0hs3mabM5lWL+R6oDUNoq4UxfAsW2GhkoGA=; b=DZ/1NcWug2cys6H/JNqGshU/Xo24P11YOh993tdanJxk9kvVnFe475NPxvy644vsLb1PxQ wMwSsJHTbaPq0eTPiBjNOzfBLFs2h27LXxtKsK8a2yUYWvLFB1C0G5JbmHrhKQVwTc47ci 2U9kF6U/XChUQn4GifaEgqdT9XXCkpPPfBYJVYTmjyE8uim/smB3dMqib28HMRiXl7lopS rQuz6SPtkxt0FmExvCi5u2hiG/EPtyZ3aDtCb2zerdVye0ceF3bEM4wAdGiU0s/jrQSHwf vWH8LewgF31ZkOGjE0rv882i4ucnJyW5i4kaOfzviMfo3wTuY0aTf8OumoNwhg== From: Luca Ceresoli Date: Thu, 06 Feb 2025 19:14:30 +0100 Subject: [PATCH v6 15/26] drm/bridge: devm_drm_of_get_bridge and drmm_of_get_bridge: automatically put the bridge MIME-Version: 1.0 Message-Id: <20250206-hotplug-drm-bridge-v6-15-9d6f2c9c3058@bootlin.com> References: <20250206-hotplug-drm-bridge-v6-0-9d6f2c9c3058@bootlin.com> In-Reply-To: <20250206-hotplug-drm-bridge-v6-0-9d6f2c9c3058@bootlin.com> To: Simona Vetter , Inki Dae , Jagan Teki , Marek Szyprowski , Catalin Marinas , Will Deacon , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Daniel Thompson , Andrzej Hajda , Jonathan Corbet , Sam Ravnborg , Boris Brezillon , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Jessica Zhang Cc: Paul Kocialkowski , Maxime Ripard , Dmitry Baryshkov , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Thomas Zimmermann , David Airlie , =?utf-8?q?Herv=C3=A9_Codina?= , Thomas Petazzoni , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Paul Kocialkowski , Luca Ceresoli X-Mailer: b4 0.14.2 X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvjedtkecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpefnuhgtrgcuvegvrhgvshholhhiuceolhhutggrrdgtvghrvghsohhlihessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnhepieeiuedvffetgfeuudelheeutefggfejieettdetteekueeuueeukeevvedvueevnecukfhppedvrgdtvdemieejtdemvddtvddtmegvrgdtudemhegrgedtmedvughfieemrgdulegvmedutgejgeenucevlhhushhtvghrufhiiigvpedufeenucfrrghrrghmpehinhgvthepvdgrtddvmeeijedtmedvtddvtdemvggrtddumeehrgegtdemvdgufheimegrudelvgemudgtjeegpdhhvghloheplgduvdejrddtrddurddungdpmhgrihhlfhhrohhmpehluhgtrgdrtggvrhgvshholhhisegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopeefkedprhgtphhtthhopegtrghtrghlihhnrdhmrghrihhnrghssegrrhhmrdgtohhmpdhrtghpthhtohepshdrhhgruhgvrhesphgvnhhguhhtrhhonhhigidruggvpdhrtghpthhtoheprghlvgigrghnughrvgdrsggvlhhlohhnihessghoohhtlhhinhdrtghom hdprhgtphhtthhopegtlhgruhguihhurdgsvgiinhgvrgesthhugihonhdruggvvhdprhgtphhtthhopehmrdhsiiihphhrohifshhkihesshgrmhhsuhhnghdrtghomhdprhgtphhtthhopegtohhrsggvtheslhifnhdrnhgvthdprhgtphhtthhopehsihhmohhnrgesfhhffihllhdrtghhpdhrtghpthhtohepughrihdquggvvhgvlheslhhishhtshdrfhhrvggvuggvshhkthhophdrohhrgh X-GND-Sasl: luca.ceresoli@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250206_101519_409643_ED8B1DC8 X-CRM114-Status: GOOD ( 16.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a devm/drmm action to these functions so the bridge reference is dropped automatically when the caller is removed. Signed-off-by: Luca Ceresoli --- This patch was added in v6. --- drivers/gpu/drm/drm_bridge.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c index f694b32ca59cb91c32846bc00b43360df41cc1ad..497ec06dfcb05ab5dee8ea5e8f1eafb9c2807612 100644 --- a/drivers/gpu/drm/drm_bridge.c +++ b/drivers/gpu/drm/drm_bridge.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -1459,6 +1460,13 @@ static int of_drm_find_bridge_by_endpoint(const struct device_node *np, return ret; } +static void devm_drm_bridge_put_void(void *data) +{ + struct drm_bridge *bridge = (struct drm_bridge *)data; + + drm_bridge_put(bridge); +} + /** * devm_drm_of_get_bridge - Return next bridge in the chain * @dev: device to tie the bridge lifetime to @@ -1469,6 +1477,10 @@ static int of_drm_find_bridge_by_endpoint(const struct device_node *np, * Given a DT node's port and endpoint number, finds the connected node * and returns the associated bridge if any. * + * The refcount of the returned bridge is incremented, but the caller does + * not have to call drm_bridge_put() when done with the bridge. It will be + * done by devres when @dev is removed. + * * Returns a pointer to the bridge if successful, or an error pointer * otherwise. */ @@ -1483,6 +1495,10 @@ struct drm_bridge *devm_drm_of_get_bridge(struct device *dev, if (ret) return ERR_PTR(ret); + ret = devm_add_action_or_reset(dev, devm_drm_bridge_put_void, bridge); + if (ret) + return ERR_PTR(ret); + return bridge; } EXPORT_SYMBOL(devm_drm_of_get_bridge); @@ -1497,6 +1513,10 @@ EXPORT_SYMBOL(devm_drm_of_get_bridge); * graph link search is not enough, e.g. for drivers that need to support * panels described only as subnodes. * + * The refcount of the returned bridge is incremented, but the caller does + * not have to call drm_bridge_put() when done with the bridge. It will be + * done by devres when @dev is removed. + * * RETURNS: * A pointer to the bridge if successful, or an error pointer otherwise. */ @@ -1513,10 +1533,21 @@ struct drm_bridge *devm_drm_of_get_bridge_by_node(struct device *dev, if (!bridge) return ERR_PTR(-ENODEV); + ret = devm_add_action_or_reset(dev, devm_drm_bridge_put_void, bridge); + if (ret) + return ERR_PTR(ret); + return bridge; } EXPORT_SYMBOL(devm_drm_of_get_bridge_by_node); +static void drmm_bridge_put_void(struct drm_device *drm, void *ptr) +{ + struct drm_bridge *bridge = ptr; + + drm_bridge_put(bridge); +} + /** * drmm_of_get_bridge - Return next bridge in the chain * @drm: device to tie the bridge lifetime to @@ -1527,6 +1558,10 @@ EXPORT_SYMBOL(devm_drm_of_get_bridge_by_node); * Given a DT node's port and endpoint number, finds the connected node * and returns the associated bridge if any. * + * The refcount of the returned bridge is incremented, but the caller does + * not have to call drm_bridge_put() when done with the bridge. It will be + * done by drmm when @dev is removed. + * * Returns a drmm managed pointer to the bridge if successful, or an error * pointer otherwise. */ @@ -1541,6 +1576,10 @@ struct drm_bridge *drmm_of_get_bridge(struct drm_device *drm, if (ret) return ERR_PTR(ret); + ret = drmm_add_action_or_reset(drm, drmm_bridge_put_void, bridge); + if (ret) + return ERR_PTR(ret); + return bridge; } EXPORT_SYMBOL(drmm_of_get_bridge);