From nobody Wed Dec 17 08:51:16 2025 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 237291E9B09 for ; Thu, 20 Mar 2025 15:42:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742485359; cv=none; b=LLfVo1+n2PigmklN/df7XCx7nuYbYzF/7vl1d0d2Dv7DwA18DujpU23hK6xA5waSnNbXF4pI+3OtzI81yNXqo43jB8zHPnDpZR7iQP4yoEGoBRc253lAAvuTVb+yn0uvL2P1RT01Wn3k2qhgH9q5PA1FDTs3RSOci7cb7Yvnfm4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742485359; c=relaxed/simple; bh=aBjsGIGpueQBsMTOcnNTnrINckzmGLWzQETsKp+rv3U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sed8MrrLgPUi098+JgTkwLqL1YjXi4ttlz61S77KUYjeh/Gg47Ub6zSK419HDlOMdOzqZOGhSR6xDV/PoTU8NrAE9rLTd2eiTdZFFHZ73m7MBUEBH44QBkYyVa/zAjzPyr6lNjSENsL+hz5twHgE9iQt2HpD9Ry5UPJQcs2+lLY= 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=MuoWdizQ; arc=none smtp.client-ip=217.70.183.201 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="MuoWdizQ" Received: by mail.gandi.net (Postfix) with ESMTPSA id 00BFB443F7; Thu, 20 Mar 2025 15:42:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1742485355; 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=u5vlr+GowG3k6kvnZqjl6Q+kHm29g1HSl0BeOMepAZM=; b=MuoWdizQB6f+QDaFA8t6AcIoH2fvem96IrOShMTv55PcoFkZOPGMrGoTbUxyjCI2TIWYaS 1RCUaQzgz/O0VhRoGa1dZo1vZvcdIV6b+c+ZujGcd93RNY/xMjo6XjrT3ZNRc2xx9EQkFQ 7r2ZEc0Fy1N2ICKQHXSirVCmf+wRNOWsOmybi12/VfxdveY+8YUsybTnmOMGfTxmXboWTi G9am+cO8qHNSip8TQ9CKuYViGk7tVksMeQob0apCK39En+f3QtpQglERg7dt+KaxE1VlPR VXLNeBcpQ7Al3dF6uKKzNnwaWt8FwEGXGSMJSvmQbwCGrwqDdWm/oZsYmCvO+w== From: Luca Ceresoli Date: Thu, 20 Mar 2025 16:42:10 +0100 Subject: [PATCH v8 1/5] drm/bridge: add devm_drm_bridge_alloc() 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: <20250320-drm-bridge-refcount-v8-1-b3ddaa9f1368@bootlin.com> References: <20250320-drm-bridge-refcount-v8-0-b3ddaa9f1368@bootlin.com> In-Reply-To: <20250320-drm-bridge-refcount-v8-0-b3ddaa9f1368@bootlin.com> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Marek Vasut , Stefan Agner , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Inki Dae , Jagan Teki , Marek Szyprowski Cc: Thomas Petazzoni , Anusha Srivatsa , Paul Kocialkowski , Dmitry Baryshkov , =?utf-8?q?Herv=C3=A9_Codina?= , Hui Pu , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Luca Ceresoli X-Mailer: b4 0.14.2 X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddugeekiedtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomhepnfhutggrucevvghrvghsohhlihcuoehluhgtrgdrtggvrhgvshholhhisegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeeiieeuvdfftefgueduleehueetgffgjeeitedtteetkeeuueeuueekveevvdeuveenucfkphepvdgrtddvmeeijedtmedvtddvtdemvggrtddumegsvgegudemleehvgejmeefgeefmeeludefvgenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvrgdtvdemieejtdemvddtvddtmegvrgdtudemsggvgedumeelhegvjeemfeegfeemledufegvpdhhvghloheplgduledvrdduieekrddujeekrdduudekngdpmhgrihhlfhhrohhmpehluhgtrgdrtggvrhgvshholhhisegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopeefuddprhgtphhtthhopehrfhhoshhssehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrnhgurhiivghjrdhhrghjuggrsehinhhtvghlrdgtohhmpdhrtghpthhtohepthiiihhmmhgvrhhmrghnnhesshhushgvrdguvgdprhgtphhtthhopehimhigs ehlihhsthhsrdhlihhnuhigrdguvghvpdhrtghpthhtohepjhgvrhhnvghjrdhskhhrrggsvggtsehgmhgrihhlrdgtohhmpdhrtghpthhtoheplhhutggrrdgtvghrvghsohhlihessghoohhtlhhinhdrtghomhdprhgtphhtthhopefnrghurhgvnhhtrdhpihhntghhrghrthesihguvggrshhonhgsohgrrhgurdgtohhmpdhrtghpthhtohephhgvrhhvvgdrtghoughinhgrsegsohhothhlihhnrdgtohhm X-GND-Sasl: luca.ceresoli@bootlin.com Add a macro to allocate and initialize a DRM bridge embedded within a private driver struct. Compared to current practice, which is based on [devm_]kzalloc() allocation followed by open-coded initialization of fields, this allows to have a common and explicit API to allocate and initialize DRM bridges. Besides being useful to consolidate bridge driver code, this is a fundamental step in preparation for adding dynamic lifetime to bridges based on refcount. Reviewed-by: Maxime Ripard Signed-off-by: Luca Ceresoli --- Changes in v8: none Changes in v7: - in v6 this was part of "drm/bridge: add support for refcounted DRM bridges", now split to a separate patch --- drivers/gpu/drm/drm_bridge.c | 22 ++++++++++++++++++++++ include/drm/drm_bridge.h | 17 +++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c index ef98e21dc593f38a2d3c67b850032ece38bec5e8..84fa1a1330cbabd309526829fff= 70971cfed1dcd 100644 --- a/drivers/gpu/drm/drm_bridge.c +++ b/drivers/gpu/drm/drm_bridge.c @@ -199,6 +199,28 @@ static DEFINE_MUTEX(bridge_lock); static LIST_HEAD(bridge_list); =20 +void *__devm_drm_bridge_alloc(struct device *dev, size_t size, size_t offs= et, + const struct drm_bridge_funcs *funcs) +{ + void *container; + struct drm_bridge *bridge; + + if (!funcs) { + dev_warn(dev, "Missing funcs pointer\n"); + return ERR_PTR(-EINVAL); + } + + container =3D devm_kzalloc(dev, size, GFP_KERNEL); + if (!container) + return ERR_PTR(-ENOMEM); + + bridge =3D container + offset; + bridge->funcs =3D funcs; + + return container; +} +EXPORT_SYMBOL(__devm_drm_bridge_alloc); + /** * drm_bridge_add - add the given bridge to the global bridge list * diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h index cdad3b78a195aa39776c93e2371217d3d3fb6064..a59277674d5a2937e324d3ce48f= 934418788053f 100644 --- a/include/drm/drm_bridge.h +++ b/include/drm/drm_bridge.h @@ -941,6 +941,23 @@ drm_priv_to_bridge(struct drm_private_obj *priv) return container_of(priv, struct drm_bridge, base); } =20 +void *__devm_drm_bridge_alloc(struct device *dev, size_t size, size_t offs= et, + const struct drm_bridge_funcs *funcs); + +/** + * devm_drm_bridge_alloc - Allocate and initialize a bridge + * @dev: struct device of the bridge device + * @type: the type of the struct which contains struct &drm_bridge + * @member: the name of the &drm_bridge within @type + * @funcs: callbacks for this bridge + * + * Returns: + * Pointer to new bridge, or ERR_PTR on failure. + */ +#define devm_drm_bridge_alloc(dev, type, member, funcs) \ + ((type *)__devm_drm_bridge_alloc(dev, sizeof(type), \ + offsetof(type, member), funcs)) + void drm_bridge_add(struct drm_bridge *bridge); int devm_drm_bridge_add(struct device *dev, struct drm_bridge *bridge); void drm_bridge_remove(struct drm_bridge *bridge); --=20 2.48.1 From nobody Wed Dec 17 08:51:16 2025 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 7482F1E98FE for ; Thu, 20 Mar 2025 15:42:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742485361; cv=none; b=a/1Q00PlPAQ2SS2AR+b/AZcwDPfICijiTnujUIyYLop8G3EKG1JmKFbN3zXOrIWlyH+ngmJ8TOAQ4w0yRWzIPgn/eJlU7qgIQJJggTNYcnrQQ7eGhq7hOm3Vpo/FEY+fQFm3e4pHKNsIR6FuOYaDek3HK3GIQ9IdmkcJvn7BMUw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742485361; c=relaxed/simple; bh=rHXaWE7iRhvqgVugYppK/9cg0Y3RTXC+2T7eFk7qF2Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MyTLw6Y0gPKJUfDAsXM9rMlJLK0tU805vaV/GqNm7JSplG4c8CIxvaHpRdOtbEJFsgAjhf/ISIiWs9Zn0J1aIr6mITdJjaGZap8u7rhc7bj7443zWi0j5nyjqZPwuI3kDHtco70I2yA7BjmpZyOPkWgbp3LsZiM9mscCp/HkKi0= 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=kmLmW1is; arc=none smtp.client-ip=217.70.183.201 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="kmLmW1is" Received: by mail.gandi.net (Postfix) with ESMTPSA id 41BE644412; Thu, 20 Mar 2025 15:42:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1742485357; 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=76ShvGbKTWCnojDi2WXjYtsq+IEWC3ZZCKont8aYmXs=; b=kmLmW1isJD2fDW3va4maqtq0Zut9KNgM1yAQVqQWKGbx68j0Z6hXG+iOBcgyk9Mhm7GRtF bqZgb/r21RFRD81PLLx6pnfwYoZo9FBFOnc37/0L0+LmD6UxpphiXszqEhqWSC667of06F 98BACERuCZG0m/iK5L7XbU+yJAT0rVK5Bv3I3+KN1SXaAeZO6qywCIprBQTEUxq6VKcCTe C5o88BxwvcRcTVlULTRO4Ghi9TcrYf0rfHFN7+gkuUliS/RSC2h/IDX2KWlNMTlgwUCSaZ akX5ykoHh2IbMwJ6IB86TkpvDmHBRBG0EOPc1XfgAL7KQTngxnNBlm4wvawEgA== From: Luca Ceresoli Date: Thu, 20 Mar 2025 16:42:11 +0100 Subject: [PATCH v8 2/5] drm/bridge: add support for refcounting 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: <20250320-drm-bridge-refcount-v8-2-b3ddaa9f1368@bootlin.com> References: <20250320-drm-bridge-refcount-v8-0-b3ddaa9f1368@bootlin.com> In-Reply-To: <20250320-drm-bridge-refcount-v8-0-b3ddaa9f1368@bootlin.com> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Marek Vasut , Stefan Agner , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Inki Dae , Jagan Teki , Marek Szyprowski Cc: Thomas Petazzoni , Anusha Srivatsa , Paul Kocialkowski , Dmitry Baryshkov , =?utf-8?q?Herv=C3=A9_Codina?= , Hui Pu , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Luca Ceresoli X-Mailer: b4 0.14.2 X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddugeekiedtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomhepnfhutggrucevvghrvghsohhlihcuoehluhgtrgdrtggvrhgvshholhhisegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeeiieeuvdfftefgueduleehueetgffgjeeitedtteetkeeuueeuueekveevvdeuveenucfkphepvdgrtddvmeeijedtmedvtddvtdemvggrtddumegsvgegudemleehvgejmeefgeefmeeludefvgenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvrgdtvdemieejtdemvddtvddtmegvrgdtudemsggvgedumeelhegvjeemfeegfeemledufegvpdhhvghloheplgduledvrdduieekrddujeekrdduudekngdpmhgrihhlfhhrohhmpehluhgtrgdrtggvrhgvshholhhisegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopeefuddprhgtphhtthhopehrfhhoshhssehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrnhgurhiivghjrdhhrghjuggrsehinhhtvghlrdgtohhmpdhrtghpthhtohepthiiihhmmhgvrhhmrghnnhesshhushgvrdguvgdprhgtphhtthhopehimhigs ehlihhsthhsrdhlihhnuhigrdguvghvpdhrtghpthhtohepjhgvrhhnvghjrdhskhhrrggsvggtsehgmhgrihhlrdgtohhmpdhrtghpthhtoheplhhutggrrdgtvghrvghsohhlihessghoohhtlhhinhdrtghomhdprhgtphhtthhopefnrghurhgvnhhtrdhpihhntghhrghrthesihguvggrshhonhgsohgrrhgurdgtohhmpdhrtghpthhtohephhgvrhhvvgdrtghoughinhgrsegsohhothhlihhnrdgtohhm X-GND-Sasl: luca.ceresoli@bootlin.com DRM bridges are currently considered as a fixed element of a DRM card, and thus their lifetime is assumed to extend for as long as the card exists. New use cases, such as hot-pluggable hardware with video bridges, require DRM bridges to be added to and removed from a DRM card without tearing the card down. This is possible for connectors already (used by DP MST), it is now needed for DRM bridges as well. As a first preliminary step, make bridges reference-counted to allow a struct drm_bridge (along with the private driver structure embedding it) to stay allocated even after the driver has been removed, until the last reference is put. Signed-off-by: Luca Ceresoli Reviewed-by: Maxime Ripard --- Changes in v8: - move back drm_bridge_get/put() to the .c file, make __drm_bridge_free private - move back drm_bridge_put_void() to .c, not used in this series outside of drm_bridge.c - remove drm_bridge_put_and_clear(), not used in this series - minor docs and coding style tweaks Changes in v7: - export drm_bridge_put_void - struct drm_bridge: use container pointer instead of container_offset - remove drm_bridge_is_refcounted() - remove all DRM_DEBUG()s - drm_bridge_get/put: accept NULL pointer and return the bridge pointer to allow pass-through calls - extract to separate patches: - the addition of drm_bridge_alloc - the addition of drm_bridge_get/put() to drm_bridge_add/remove() - the addition of drm_bridge_get/put() to drm_bridge_attach/detach() - fix a typo, slightly improve kerneldoc Changes in v6: - use drm_warn, not WARN_ON (Jani Nikula) - Add devm_drm_bridge_alloc() to replace drm_bridge_init() (similar to drmm_encoder_alloc) - Remove .destroy func: deallocation is done via the struct offset computed by the devm_drm_bridge_alloc() macro - use fixed free callback, as the same callback is used in all cases anyway (remove free_cb, add bool is_refcounted) - add drm_bridge_get/put() to drm_bridge_attach/detach() (add the bridge to a list) - make some DRM_DEBUG() strings more informative This patch was added in v5. --- drivers/gpu/drm/drm_bridge.c | 72 ++++++++++++++++++++++++++++++++++++++++= +++- include/drm/drm_bridge.h | 19 ++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c index 84fa1a1330cbabd309526829fff70971cfed1dcd..2f2ecb73308e601b1a53ec8e711= 0933cef59b5da 100644 --- a/drivers/gpu/drm/drm_bridge.c +++ b/drivers/gpu/drm/drm_bridge.c @@ -199,23 +199,93 @@ static DEFINE_MUTEX(bridge_lock); static LIST_HEAD(bridge_list); =20 +static void __drm_bridge_free(struct kref *kref) +{ + struct drm_bridge *bridge =3D container_of(kref, struct drm_bridge, refco= unt); + + kfree(bridge->container); +} + +/** + * drm_bridge_get - Acquire a bridge reference + * @bridge: DRM bridge + * + * This function increments the bridge's refcount. + * + * Returns: + * Pointer to @bridge. + */ +struct drm_bridge *drm_bridge_get(struct drm_bridge *bridge) +{ + if (!bridge) + return bridge; + + kref_get(&bridge->refcount); + + return bridge; +} +EXPORT_SYMBOL(drm_bridge_get); + +/** + * drm_bridge_put - Release a bridge reference + * @bridge: DRM bridge + * + * This function decrements the bridge's reference count and frees the + * object if the reference count drops to zero. + * + * Returns: + * Pointer to @bridge. + */ +struct drm_bridge *drm_bridge_put(struct drm_bridge *bridge) +{ + if (!bridge) + return bridge; + + kref_put(&bridge->refcount, __drm_bridge_free); + + return bridge; +} +EXPORT_SYMBOL(drm_bridge_put); + +/** + * drm_bridge_put_void - wrapper to drm_bridge_put() taking a void pointer + * + * @data: pointer to @struct drm_bridge, cast to a void pointer + * + * Wrapper of drm_bridge_put() to be used when a function taking a void + * pointer is needed, for example as a devm action. + */ +static void drm_bridge_put_void(void *data) +{ + struct drm_bridge *bridge =3D (struct drm_bridge *)data; + + drm_bridge_put(bridge); +} + void *__devm_drm_bridge_alloc(struct device *dev, size_t size, size_t offs= et, const struct drm_bridge_funcs *funcs) { void *container; struct drm_bridge *bridge; + int err; =20 if (!funcs) { dev_warn(dev, "Missing funcs pointer\n"); return ERR_PTR(-EINVAL); } =20 - container =3D devm_kzalloc(dev, size, GFP_KERNEL); + container =3D kzalloc(size, GFP_KERNEL); if (!container) return ERR_PTR(-ENOMEM); =20 bridge =3D container + offset; + bridge->container =3D container; bridge->funcs =3D funcs; + kref_init(&bridge->refcount); + + err =3D devm_add_action_or_reset(dev, drm_bridge_put_void, bridge); + if (err) + return ERR_PTR(err); =20 return container; } diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h index a59277674d5a2937e324d3ce48f934418788053f..076f40c17dd86b224bbe6517b71= f1aa6c24bfbd7 100644 --- a/include/drm/drm_bridge.h +++ b/include/drm/drm_bridge.h @@ -840,6 +840,18 @@ struct drm_bridge { const struct drm_bridge_timings *timings; /** @funcs: control functions */ const struct drm_bridge_funcs *funcs; + + /** + * @container: Pointer to the private driver struct embedding this + * @struct drm_bridge. + */ + void *container; + + /** + * @refcount: reference count of users referencing this bridge. + */ + struct kref refcount; + /** @driver_private: pointer to the bridge driver's internal context */ void *driver_private; /** @ops: bitmask of operations supported by the bridge */ @@ -941,6 +953,9 @@ drm_priv_to_bridge(struct drm_private_obj *priv) return container_of(priv, struct drm_bridge, base); } =20 +struct drm_bridge *drm_bridge_get(struct drm_bridge *bridge); +struct drm_bridge *drm_bridge_put(struct drm_bridge *bridge); + void *__devm_drm_bridge_alloc(struct device *dev, size_t size, size_t offs= et, const struct drm_bridge_funcs *funcs); =20 @@ -951,6 +966,10 @@ void *__devm_drm_bridge_alloc(struct device *dev, size= _t size, size_t offset, * @member: the name of the &drm_bridge within @type * @funcs: callbacks for this bridge * + * The reference count of the returned bridge is initialized to 1. This + * reference will be automatically dropped via devm (by calling + * drm_bridge_put()) when @dev is removed. + * * Returns: * Pointer to new bridge, or ERR_PTR on failure. */ --=20 2.48.1 From nobody Wed Dec 17 08:51:16 2025 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 3295C21D3E2 for ; Thu, 20 Mar 2025 15:42:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742485363; cv=none; b=K+ELCnZDCoO0Ok1yy9vyp7eji+vSJMRBnL7l2gj3RWB0G59KK4J2W3X4fp5qutZcdh6GEYKm1LPXj9HCmp0LosAhk2L0xDINdlwLXillEr00QQNfg1YtENczzfNMHQ/06i8EA00zQRLJLgr1c38OFc1+nsYcbsWziq02wD9N/80= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742485363; c=relaxed/simple; bh=h/LzKZbNTgj+gZc92rlcauCerhCDhQNVV9eF+GpfrE8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TOIMfFYScWe0eMNSbOcBsOtoMAwxT0WjGyMQIgGOrLdhEbyCQRhlXtX9qA4IKJKZlyfPMbAc9sJGhwRh0uP3DYGebi+Zkr0enFXo9mlCA5s4CCKn4zmpVvebLJH+lIaipvGk+9rR+rXaIFGVtc24mJbRzW+aFzoKE/m2WJ3r4Z0= 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=BOwk98/T; arc=none smtp.client-ip=217.70.183.201 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="BOwk98/T" Received: by mail.gandi.net (Postfix) with ESMTPSA id 7E2B444417; Thu, 20 Mar 2025 15:42:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1742485359; 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=jyBNDLsArbdd7WHk93rkhCfp9ThfO49YHtAhELFf8JY=; b=BOwk98/TpGkOxzJx4oiUhpGhy8r0YMvaGQJYOINSzpbd20HMenb3xP12VjS//hVhI72Iam t9Dpvqpn8S9iRISG6Tg5phGO/QXvlbJB2vfZGxLCXG957uZvZcbWhedktWUQnkjPAoXxIs HkQAv1VRQ7IgMzM3YKaxo4NQO0jqfvwhuwPuz9VTzVxZXedGBuvGeTx06uh/oLs4vzRkd5 JxTYtaW0T0J4NlVjtMed+UKicoT37q+vyPsn0wG71dm+a7wyCghXMAbpy1ZMeukJ1pdC8t Qkzr8akHHSnnpISG93yuGxJDUJ54W0Ipu4fHEWwA6kW7Ab289RadMxvwAhSdfQ== From: Luca Ceresoli Date: Thu, 20 Mar 2025 16:42:12 +0100 Subject: [PATCH v8 3/5] drm/bridge: deprecate old-style bridge allocation 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: <20250320-drm-bridge-refcount-v8-3-b3ddaa9f1368@bootlin.com> References: <20250320-drm-bridge-refcount-v8-0-b3ddaa9f1368@bootlin.com> In-Reply-To: <20250320-drm-bridge-refcount-v8-0-b3ddaa9f1368@bootlin.com> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Marek Vasut , Stefan Agner , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Inki Dae , Jagan Teki , Marek Szyprowski Cc: Thomas Petazzoni , Anusha Srivatsa , Paul Kocialkowski , Dmitry Baryshkov , =?utf-8?q?Herv=C3=A9_Codina?= , Hui Pu , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Luca Ceresoli X-Mailer: b4 0.14.2 X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddugeekiedtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomhepnfhutggrucevvghrvghsohhlihcuoehluhgtrgdrtggvrhgvshholhhisegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeeiieeuvdfftefgueduleehueetgffgjeeitedtteetkeeuueeuueekveevvdeuveenucfkphepvdgrtddvmeeijedtmedvtddvtdemvggrtddumegsvgegudemleehvgejmeefgeefmeeludefvgenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvrgdtvdemieejtdemvddtvddtmegvrgdtudemsggvgedumeelhegvjeemfeegfeemledufegvpdhhvghloheplgduledvrdduieekrddujeekrdduudekngdpmhgrihhlfhhrohhmpehluhgtrgdrtggvrhgvshholhhisegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopeefuddprhgtphhtthhopehrfhhoshhssehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrnhgurhiivghjrdhhrghjuggrsehinhhtvghlrdgtohhmpdhrtghpthhtohepthiiihhmmhgvrhhmrghnnhesshhushgvrdguvgdprhgtphhtthhopehimhigs ehlihhsthhsrdhlihhnuhigrdguvghvpdhrtghpthhtohepjhgvrhhnvghjrdhskhhrrggsvggtsehgmhgrihhlrdgtohhmpdhrtghpthhtoheplhhutggrrdgtvghrvghsohhlihessghoohhtlhhinhdrtghomhdprhgtphhtthhopefnrghurhgvnhhtrdhpihhntghhrghrthesihguvggrshhonhgsohgrrhgurdgtohhmpdhrtghpthhtohephhgvrhhvvgdrtghoughinhgrsegsohhothhlihhnrdgtohhm X-GND-Sasl: luca.ceresoli@bootlin.com All DRM bridges are now supposed to be allocated using devm_drm_bridge_alloc(), which is cleaner and necessary to support refcounting. Deprecate old school allocation using kzalloc and derivatives. In the absence of a drm_bridge_init() or such initialization function, document the deprecation on the first DRM bridge core function that is called after allocation, i.e. drm_bridge_add(). Suggested-by: Maxime Ripard Signed-off-by: Luca Ceresoli --- This patch was added in v8. --- drivers/gpu/drm/drm_bridge.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c index 2f2ecb73308e601b1a53ec8e7110933cef59b5da..17659b1cbdeae04e10b76f2aabc= 8ebba65c4f6e1 100644 --- a/drivers/gpu/drm/drm_bridge.c +++ b/drivers/gpu/drm/drm_bridge.c @@ -295,6 +295,10 @@ EXPORT_SYMBOL(__devm_drm_bridge_alloc); * drm_bridge_add - add the given bridge to the global bridge list * * @bridge: bridge control structure + * + * The bridge to be added must have been allocated by + * devm_drm_bridge_alloc(). Old-style allocation by kzalloc(), + * devm_kzalloc() and similar is deprecated. */ void drm_bridge_add(struct drm_bridge *bridge) { --=20 2.48.1 From nobody Wed Dec 17 08:51:16 2025 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 66649223311 for ; Thu, 20 Mar 2025 15:42:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742485365; cv=none; b=DiOb444SW2aspCovvXBziVpBT5zewP4rx4CK/L8nITJZVWldayh40eHwtIKqG5WAZQ0UjhdJqvFtDPtOgx+ijDcAOhHQqotzbOwhUoUgUC6TVo6Duvv/Ti0WnfiYuCNsvpdhORd7fOewxA9Mq0hFOjsc38H9urFNDiSEvgTU2b8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742485365; c=relaxed/simple; bh=edeD0kCE2+zQk3WOoYvyPNq5MzvukI6Cr/l1Z5V0L2A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MNZ+7GGOo5zuKs6Yd28lvgnVGcwvr4Xf02exfSndvQ/BO7APHBgPsRTWLwIOMFjaEat/Vo3R9FsUEJazH/FUMs/13T/aME6RKtgV3duFjCZ0oXRXVWRoSvKw4JMdFIhYlny/Cs4F6V5tYxaqgCmydfSqqfxgoN7XKKpCrAIrzhc= 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=l8hW87W1; arc=none smtp.client-ip=217.70.183.201 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="l8hW87W1" Received: by mail.gandi.net (Postfix) with ESMTPSA id B5BD144422; Thu, 20 Mar 2025 15:42:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1742485361; 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=xu+uoSfSOhkoTShUNDlJziaFGObfGRc5heue1JT/SkA=; b=l8hW87W1U80LDg6/V28vPyf0zY+gWD7Ef2JWgTmvbX9ueX4P/4BKn3ggyru4OjfnXHUyk1 nxJIu05MFBofXfTFVi3dedj6ZMrwdqfe5H5H5nx3CQWsrnotsRZvHoMsQhmABKxgrdRc2H LcK59kJpDObXEvaiH/b4bchbxy/oa3ECxPkf0reTMaXJaAg83YK7iyGzm723aTGo/Gg311 LKqi70Km3XZlmLvym5YZ7DuY0c/JWfPapGh5SvUo9J+BbFx5eBxqibs8/OxulD/U/VJyIJ YqTuyx9VS/+qjTx8IofKcgf5zWVqVVnMYfVL3t8FQvYFWZ8Wb8CkR0s7xQYPhw== From: Luca Ceresoli Date: Thu, 20 Mar 2025 16:42:13 +0100 Subject: [PATCH v8 4/5] drm/bridge: ti-sn65dsi83: use dynamic lifetime management 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: <20250320-drm-bridge-refcount-v8-4-b3ddaa9f1368@bootlin.com> References: <20250320-drm-bridge-refcount-v8-0-b3ddaa9f1368@bootlin.com> In-Reply-To: <20250320-drm-bridge-refcount-v8-0-b3ddaa9f1368@bootlin.com> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Marek Vasut , Stefan Agner , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Inki Dae , Jagan Teki , Marek Szyprowski Cc: Thomas Petazzoni , Anusha Srivatsa , Paul Kocialkowski , Dmitry Baryshkov , =?utf-8?q?Herv=C3=A9_Codina?= , Hui Pu , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Luca Ceresoli X-Mailer: b4 0.14.2 X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddugeekiedtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomhepnfhutggrucevvghrvghsohhlihcuoehluhgtrgdrtggvrhgvshholhhisegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeeiieeuvdfftefgueduleehueetgffgjeeitedtteetkeeuueeuueekveevvdeuveenucfkphepvdgrtddvmeeijedtmedvtddvtdemvggrtddumegsvgegudemleehvgejmeefgeefmeeludefvgenucevlhhushhtvghrufhiiigvpeefnecurfgrrhgrmhepihhnvghtpedvrgdtvdemieejtdemvddtvddtmegvrgdtudemsggvgedumeelhegvjeemfeegfeemledufegvpdhhvghloheplgduledvrdduieekrddujeekrdduudekngdpmhgrihhlfhhrohhmpehluhgtrgdrtggvrhgvshholhhisegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopeefuddprhgtphhtthhopehrfhhoshhssehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrnhgurhiivghjrdhhrghjuggrsehinhhtvghlrdgtohhmpdhrtghpthhtohepthiiihhmmhgvrhhmrghnnhesshhushgvrdguvgdprhgtphhtthhopehimhigs ehlihhsthhsrdhlihhnuhigrdguvghvpdhrtghpthhtohepjhgvrhhnvghjrdhskhhrrggsvggtsehgmhgrihhlrdgtohhmpdhrtghpthhtoheplhhutggrrdgtvghrvghsohhlihessghoohhtlhhinhdrtghomhdprhgtphhtthhopefnrghurhgvnhhtrdhpihhntghhrghrthesihguvggrshhonhgsohgrrhgurdgtohhmpdhrtghpthhtohephhgvrhhvvgdrtghoughinhgrsegsohhothhlihhnrdgtohhm X-GND-Sasl: luca.ceresoli@bootlin.com Allow this bridge to be removable without dangling pointers and use-after-free, together with proper use of drm_bridge_get() and _put() by consumers. Reviewed-by: Maxime Ripard Signed-off-by: Luca Ceresoli --- Changes in v8: none Changes in v7: none Changed in v6: - Update to use devm_drm_bridge_alloc(), remove .destroy This patch was added in v5. --- drivers/gpu/drm/bridge/ti-sn65dsi83.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi83.c b/drivers/gpu/drm/bridge= /ti-sn65dsi83.c index 6e0ba427c2582c33f7b95634a18dcda9ac28267f..4efb62376e196d8bb5e9f58867e= 5c0e1624391db 100644 --- a/drivers/gpu/drm/bridge/ti-sn65dsi83.c +++ b/drivers/gpu/drm/bridge/ti-sn65dsi83.c @@ -947,9 +947,9 @@ static int sn65dsi83_probe(struct i2c_client *client) struct sn65dsi83 *ctx; int ret; =20 - ctx =3D devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); - if (!ctx) - return -ENOMEM; + ctx =3D devm_drm_bridge_alloc(dev, struct sn65dsi83, bridge, &sn65dsi83_f= uncs); + if (IS_ERR(ctx)) + return PTR_ERR(ctx); =20 ctx->dev =3D dev; INIT_WORK(&ctx->reset_work, sn65dsi83_reset_work); @@ -989,7 +989,6 @@ static int sn65dsi83_probe(struct i2c_client *client) dev_set_drvdata(dev, ctx); i2c_set_clientdata(client, ctx); =20 - ctx->bridge.funcs =3D &sn65dsi83_funcs; ctx->bridge.of_node =3D dev->of_node; ctx->bridge.pre_enable_prev_first =3D true; ctx->bridge.type =3D DRM_MODE_CONNECTOR_LVDS; --=20 2.48.1 From nobody Wed Dec 17 08:51:16 2025 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 AFD4A22424D for ; Thu, 20 Mar 2025 15:42:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742485367; cv=none; b=IQ6VsiXJKlGmwh/dgQTBE44HiwE2p+4JMojM/QN5DLIeCSPcg92zdDgic9eaa8cPD2vKWO1Z6BItCApaiQoeA1lGPwVRsERnNpSk7pl62ENMghHBi2b3EXWC4O+LlyuQjuDDj1MNubLnf70D+DNI8r5iVSMTvcxnd05Odcnpk+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742485367; c=relaxed/simple; bh=YD8k1Vkj2fa7j8F6a+2Iof/295jI2+0yrYEj0GcOhHA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gaLfaePK7f5PCKg/iVWcomr7C/hWzdqWVWFL6HWDdWY+ph/dLPDMCkVIoup4wiNO848cv4FOTNbzXeHbMZi5tXhQHBQAcsP96ByMLEkKbDJLYTMoX/e2jPpPo1ePTWKVrTyb9z8cZQ6RqN3vw8UVVgWTNBv7hn3OsFI0Sfjn5zY= 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=HvEc1FLO; arc=none smtp.client-ip=217.70.183.201 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="HvEc1FLO" Received: by mail.gandi.net (Postfix) with ESMTPSA id EEE8444408; Thu, 20 Mar 2025 15:42:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1742485364; 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=XgB3E9/XVLuIu4T8MuTOjtqbhqCUgDiA94vVvHuz8zk=; b=HvEc1FLOCYSH103JmeD8Ac+x9C0qJ0Yb8aCnQUAeURjilBPqBtie+pEAoS3bBCZ1mMTRzO w+13OS9sCiWwoSsG4oQyPRAWozN+S0y5TTrnLN483RDVVK3dg4ttRLLEGBGH2Qa/11fzP0 8zipHiAyUGjNh3G9uDEHZJqYx6tcS4+Zk0ymioLVp0h2VmI0td4ocYdnre332hfOQznbj4 yWaX5AYsC4VtWUiTeSeSQZAYSMN+5KzjBk0lg3nvvUiRRXgYdx0gIRF3NUupoEESpC9jjO gYD7P8qZob3Tf2zlkopohKCm/FfM4FQ5CyDpfb2F/DPOvaKovj04kko/z3htHw== From: Luca Ceresoli Date: Thu, 20 Mar 2025 16:42:14 +0100 Subject: [PATCH v8 5/5] drm/bridge: samsung-dsim: use dynamic lifetime management 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: <20250320-drm-bridge-refcount-v8-5-b3ddaa9f1368@bootlin.com> References: <20250320-drm-bridge-refcount-v8-0-b3ddaa9f1368@bootlin.com> In-Reply-To: <20250320-drm-bridge-refcount-v8-0-b3ddaa9f1368@bootlin.com> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Marek Vasut , Stefan Agner , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Inki Dae , Jagan Teki , Marek Szyprowski Cc: Thomas Petazzoni , Anusha Srivatsa , Paul Kocialkowski , Dmitry Baryshkov , =?utf-8?q?Herv=C3=A9_Codina?= , Hui Pu , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Luca Ceresoli X-Mailer: b4 0.14.2 X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddugeekiedtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomhepnfhutggrucevvghrvghsohhlihcuoehluhgtrgdrtggvrhgvshholhhisegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeeiieeuvdfftefgueduleehueetgffgjeeitedtteetkeeuueeuueekveevvdeuveenucfkphepvdgrtddvmeeijedtmedvtddvtdemvggrtddumegsvgegudemleehvgejmeefgeefmeeludefvgenucevlhhushhtvghrufhiiigvpeefnecurfgrrhgrmhepihhnvghtpedvrgdtvdemieejtdemvddtvddtmegvrgdtudemsggvgedumeelhegvjeemfeegfeemledufegvpdhhvghloheplgduledvrdduieekrddujeekrdduudekngdpmhgrihhlfhhrohhmpehluhgtrgdrtggvrhgvshholhhisegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopeefuddprhgtphhtthhopehrfhhoshhssehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrnhgurhiivghjrdhhrghjuggrsehinhhtvghlrdgtohhmpdhrtghpthhtohepthiiihhmmhgvrhhmrghnnhesshhushgvrdguvgdprhgtphhtthhopehimhigs ehlihhsthhsrdhlihhnuhigrdguvghvpdhrtghpthhtohepjhgvrhhnvghjrdhskhhrrggsvggtsehgmhgrihhlrdgtohhmpdhrtghpthhtoheplhhutggrrdgtvghrvghsohhlihessghoohhtlhhinhdrtghomhdprhgtphhtthhopefnrghurhgvnhhtrdhpihhntghhrghrthesihguvggrshhonhgsohgrrhgurdgtohhmpdhrtghpthhtohephhgvrhhvvgdrtghoughinhgrsegsohhothhlihhnrdgtohhm X-GND-Sasl: luca.ceresoli@bootlin.com Allow this bridge to be removable without dangling pointers and use-after-free, together with proper use of drm_bridge_get() and _put() by consumers. Reviewed-by: Maxime Ripard Signed-off-by: Luca Ceresoli --- Changes in v8: none This patch was added in v7. --- drivers/gpu/drm/bridge/samsung-dsim.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/bridge/samsung-dsim.c b/drivers/gpu/drm/bridge= /samsung-dsim.c index 55ac6bd5da08c037aa7974df679d51e72bc54faf..0014c497e3fe7d8349a119dbdda= 30d65d816cccf 100644 --- a/drivers/gpu/drm/bridge/samsung-dsim.c +++ b/drivers/gpu/drm/bridge/samsung-dsim.c @@ -1936,9 +1936,9 @@ int samsung_dsim_probe(struct platform_device *pdev) struct samsung_dsim *dsi; int ret, i; =20 - dsi =3D devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL); - if (!dsi) - return -ENOMEM; + dsi =3D devm_drm_bridge_alloc(dev, struct samsung_dsim, bridge, &samsung_= dsim_bridge_funcs); + if (IS_ERR(dsi)) + return PTR_ERR(dsi); =20 init_completion(&dsi->completed); spin_lock_init(&dsi->transfer_lock); @@ -2008,7 +2008,6 @@ int samsung_dsim_probe(struct platform_device *pdev) =20 pm_runtime_enable(dev); =20 - dsi->bridge.funcs =3D &samsung_dsim_bridge_funcs; dsi->bridge.of_node =3D dev->of_node; dsi->bridge.type =3D DRM_MODE_CONNECTOR_DSI; =20 --=20 2.48.1