* [PATCH v8 0/5] drm/bridge: add devm_drm_bridge_alloc() with bridge refcount
@ 2025-03-20 15:42 Luca Ceresoli
2025-03-20 15:42 ` [PATCH v8 1/5] drm/bridge: add devm_drm_bridge_alloc() Luca Ceresoli
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Luca Ceresoli @ 2025-03-20 15:42 UTC (permalink / raw)
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, Hervé Codina, Hui Pu, dri-devel,
linux-kernel, imx, linux-arm-kernel, Luca Ceresoli
This series improves the way DRM bridges are allocated and initialized and
makes them reference-counted. The goal of reference counting is to avoid
use-after-free by drivers which got a pointer to a bridge and keep it
stored and used even after the bridge has been deallocated.
The overall goal is supporting Linux devices with a DRM pipeline whose
final components can be hot-plugged and hot-unplugged, including one or
more bridges. For more details see the big picture [0].
DRM bridge drivers will have to be adapted to the new API -- the change is
trivial for most cases. This series converts two of them to serve as an
example. The remaining ones will be done as a follow-up after this first
part is merged.
After that, refcounting will have to be added on the two sides: all
functions returning a bridge pointer and all code obtaining such a
pointer. A few examples have been sent in v7 (link below), they are OK, but
I removed them from v8 because they must be merged only after converting
all bridges.
Here's the grand plan:
A. add new alloc API and refcounting (this series, at least patches 1-3)
B. after (A), convert all bridge drivers to new API
C. after (A), add documentation and kunit tests
D. after (B), add get/put to drm_bridge_add/remove() + attach/detech()
(patches 3-4 in the v7 series)
E. after (B), convert accessors (including patches 5-9 in the v7 series
which convert drm_bridge_chain_get_first_bridge() and its users);
this is a large work and can be done in chunks
Series layout:
1. Add the new API and refcounting:
drm/bridge: add devm_drm_bridge_alloc()
drm/bridge: add support for refcounting
drm/bridge: deprecate old-style bridge allocation
2. convert a few bridge drivers (bridge providers) to the new API:
drm/bridge: ti-sn65dsi83: use dynamic lifetime management
drm/bridge: samsung-dsim: use dynamic lifetime management
[0] https://lore.kernel.org/dri-devel/20250206-hotplug-drm-bridge-v6-0-9d6f2c9c3058@bootlin.com/
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
Changes in v8:
- Applied requested changes to patch 2
- Add R-by to other patches
- Removed v7 patches 3-9: they are OK but must wait until all bridge
drivers are converted to the new API
- Added patch to deprecate old-style bridge allocation
- Link to v7: https://lore.kernel.org/r/20250314-drm-bridge-refcount-v7-0-152571f8c694@bootlin.com
---
Luca Ceresoli (5):
drm/bridge: add devm_drm_bridge_alloc()
drm/bridge: add support for refcounting
drm/bridge: deprecate old-style bridge allocation
drm/bridge: ti-sn65dsi83: use dynamic lifetime management
drm/bridge: samsung-dsim: use dynamic lifetime management
drivers/gpu/drm/bridge/samsung-dsim.c | 7 ++-
drivers/gpu/drm/bridge/ti-sn65dsi83.c | 7 ++-
drivers/gpu/drm/drm_bridge.c | 96 +++++++++++++++++++++++++++++++++++
include/drm/drm_bridge.h | 36 +++++++++++++
4 files changed, 138 insertions(+), 8 deletions(-)
---
base-commit: c940d00c7306a77ec293661abca634756207c885
change-id: 20250314-drm-bridge-refcount-58d9503503f6
Best regards,
--
Luca Ceresoli <luca.ceresoli@bootlin.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v8 1/5] drm/bridge: add devm_drm_bridge_alloc()
2025-03-20 15:42 [PATCH v8 0/5] drm/bridge: add devm_drm_bridge_alloc() with bridge refcount Luca Ceresoli
@ 2025-03-20 15:42 ` Luca Ceresoli
2025-03-20 15:42 ` [PATCH v8 2/5] drm/bridge: add support for refcounting Luca Ceresoli
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Luca Ceresoli @ 2025-03-20 15:42 UTC (permalink / raw)
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, Hervé Codina, Hui Pu, dri-devel,
linux-kernel, imx, linux-arm-kernel, Luca Ceresoli
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 <mripard@kernel.org>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
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..84fa1a1330cbabd309526829fff70971cfed1dcd 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);
+void *__devm_drm_bridge_alloc(struct device *dev, size_t size, size_t offset,
+ 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 = devm_kzalloc(dev, size, GFP_KERNEL);
+ if (!container)
+ return ERR_PTR(-ENOMEM);
+
+ bridge = container + offset;
+ bridge->funcs = 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..a59277674d5a2937e324d3ce48f934418788053f 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);
}
+void *__devm_drm_bridge_alloc(struct device *dev, size_t size, size_t offset,
+ 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);
--
2.48.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v8 2/5] drm/bridge: add support for refcounting
2025-03-20 15:42 [PATCH v8 0/5] drm/bridge: add devm_drm_bridge_alloc() with bridge refcount Luca Ceresoli
2025-03-20 15:42 ` [PATCH v8 1/5] drm/bridge: add devm_drm_bridge_alloc() Luca Ceresoli
@ 2025-03-20 15:42 ` Luca Ceresoli
2025-03-21 9:54 ` Maxime Ripard
2025-03-20 15:42 ` [PATCH v8 3/5] drm/bridge: deprecate old-style bridge allocation Luca Ceresoli
` (2 subsequent siblings)
4 siblings, 1 reply; 8+ messages in thread
From: Luca Ceresoli @ 2025-03-20 15:42 UTC (permalink / raw)
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, Hervé Codina, Hui Pu, dri-devel,
linux-kernel, imx, linux-arm-kernel, Luca Ceresoli
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 <luca.ceresoli@bootlin.com>
---
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..2f2ecb73308e601b1a53ec8e7110933cef59b5da 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);
+static void __drm_bridge_free(struct kref *kref)
+{
+ struct drm_bridge *bridge = container_of(kref, struct drm_bridge, refcount);
+
+ 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 = (struct drm_bridge *)data;
+
+ drm_bridge_put(bridge);
+}
+
void *__devm_drm_bridge_alloc(struct device *dev, size_t size, size_t offset,
const struct drm_bridge_funcs *funcs)
{
void *container;
struct drm_bridge *bridge;
+ int err;
if (!funcs) {
dev_warn(dev, "Missing funcs pointer\n");
return ERR_PTR(-EINVAL);
}
- container = devm_kzalloc(dev, size, GFP_KERNEL);
+ container = kzalloc(size, GFP_KERNEL);
if (!container)
return ERR_PTR(-ENOMEM);
bridge = container + offset;
+ bridge->container = container;
bridge->funcs = funcs;
+ kref_init(&bridge->refcount);
+
+ err = devm_add_action_or_reset(dev, drm_bridge_put_void, bridge);
+ if (err)
+ return ERR_PTR(err);
return container;
}
diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h
index a59277674d5a2937e324d3ce48f934418788053f..076f40c17dd86b224bbe6517b71f1aa6c24bfbd7 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);
}
+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 offset,
const struct drm_bridge_funcs *funcs);
@@ -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.
*/
--
2.48.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v8 3/5] drm/bridge: deprecate old-style bridge allocation
2025-03-20 15:42 [PATCH v8 0/5] drm/bridge: add devm_drm_bridge_alloc() with bridge refcount Luca Ceresoli
2025-03-20 15:42 ` [PATCH v8 1/5] drm/bridge: add devm_drm_bridge_alloc() Luca Ceresoli
2025-03-20 15:42 ` [PATCH v8 2/5] drm/bridge: add support for refcounting Luca Ceresoli
@ 2025-03-20 15:42 ` Luca Ceresoli
2025-03-20 15:42 ` [PATCH v8 4/5] drm/bridge: ti-sn65dsi83: use dynamic lifetime management Luca Ceresoli
2025-03-20 15:42 ` [PATCH v8 5/5] drm/bridge: samsung-dsim: " Luca Ceresoli
4 siblings, 0 replies; 8+ messages in thread
From: Luca Ceresoli @ 2025-03-20 15:42 UTC (permalink / raw)
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, Hervé Codina, Hui Pu, dri-devel,
linux-kernel, imx, linux-arm-kernel, Luca Ceresoli
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 <mripard@kernel.org>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
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..17659b1cbdeae04e10b76f2aabc8ebba65c4f6e1 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)
{
--
2.48.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v8 4/5] drm/bridge: ti-sn65dsi83: use dynamic lifetime management
2025-03-20 15:42 [PATCH v8 0/5] drm/bridge: add devm_drm_bridge_alloc() with bridge refcount Luca Ceresoli
` (2 preceding siblings ...)
2025-03-20 15:42 ` [PATCH v8 3/5] drm/bridge: deprecate old-style bridge allocation Luca Ceresoli
@ 2025-03-20 15:42 ` Luca Ceresoli
2025-03-20 15:42 ` [PATCH v8 5/5] drm/bridge: samsung-dsim: " Luca Ceresoli
4 siblings, 0 replies; 8+ messages in thread
From: Luca Ceresoli @ 2025-03-20 15:42 UTC (permalink / raw)
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, Hervé Codina, Hui Pu, dri-devel,
linux-kernel, imx, linux-arm-kernel, Luca Ceresoli
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 <mripard@kernel.org>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
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..4efb62376e196d8bb5e9f58867e5c0e1624391db 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;
- ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
- if (!ctx)
- return -ENOMEM;
+ ctx = devm_drm_bridge_alloc(dev, struct sn65dsi83, bridge, &sn65dsi83_funcs);
+ if (IS_ERR(ctx))
+ return PTR_ERR(ctx);
ctx->dev = 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);
- ctx->bridge.funcs = &sn65dsi83_funcs;
ctx->bridge.of_node = dev->of_node;
ctx->bridge.pre_enable_prev_first = true;
ctx->bridge.type = DRM_MODE_CONNECTOR_LVDS;
--
2.48.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v8 5/5] drm/bridge: samsung-dsim: use dynamic lifetime management
2025-03-20 15:42 [PATCH v8 0/5] drm/bridge: add devm_drm_bridge_alloc() with bridge refcount Luca Ceresoli
` (3 preceding siblings ...)
2025-03-20 15:42 ` [PATCH v8 4/5] drm/bridge: ti-sn65dsi83: use dynamic lifetime management Luca Ceresoli
@ 2025-03-20 15:42 ` Luca Ceresoli
4 siblings, 0 replies; 8+ messages in thread
From: Luca Ceresoli @ 2025-03-20 15:42 UTC (permalink / raw)
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, Hervé Codina, Hui Pu, dri-devel,
linux-kernel, imx, linux-arm-kernel, Luca Ceresoli
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 <mripard@kernel.org>
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
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..0014c497e3fe7d8349a119dbdda30d65d816cccf 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;
- dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL);
- if (!dsi)
- return -ENOMEM;
+ dsi = devm_drm_bridge_alloc(dev, struct samsung_dsim, bridge, &samsung_dsim_bridge_funcs);
+ if (IS_ERR(dsi))
+ return PTR_ERR(dsi);
init_completion(&dsi->completed);
spin_lock_init(&dsi->transfer_lock);
@@ -2008,7 +2008,6 @@ int samsung_dsim_probe(struct platform_device *pdev)
pm_runtime_enable(dev);
- dsi->bridge.funcs = &samsung_dsim_bridge_funcs;
dsi->bridge.of_node = dev->of_node;
dsi->bridge.type = DRM_MODE_CONNECTOR_DSI;
--
2.48.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v8 2/5] drm/bridge: add support for refcounting
2025-03-20 15:42 ` [PATCH v8 2/5] drm/bridge: add support for refcounting Luca Ceresoli
@ 2025-03-21 9:54 ` Maxime Ripard
2025-03-21 18:21 ` Luca Ceresoli
0 siblings, 1 reply; 8+ messages in thread
From: Maxime Ripard @ 2025-03-21 9:54 UTC (permalink / raw)
To: Luca Ceresoli
Cc: dri-devel, imx, linux-arm-kernel, linux-kernel, Andrzej Hajda,
Anusha Srivatsa, David Airlie, Dmitry Baryshkov, Fabio Estevam,
Hervé Codina, Hui Pu, Inki Dae, Jagan Teki, Jernej Skrabec,
Jonas Karlman, Laurent Pinchart, Maarten Lankhorst,
Marek Szyprowski, Marek Vasut, Maxime Ripard, Neil Armstrong,
Paul Kocialkowski, Pengutronix Kernel Team, Robert Foss,
Sascha Hauer, Shawn Guo, Simona Vetter, Stefan Agner,
Thomas Petazzoni, Thomas Zimmermann
On Thu, 20 Mar 2025 16:42:11 +0100, Luca Ceresoli wrote:
> 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
>
> [ ... ]
Reviewed-by: Maxime Ripard <mripard@kernel.org>
Thanks!
Maxime
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v8 2/5] drm/bridge: add support for refcounting
2025-03-21 9:54 ` Maxime Ripard
@ 2025-03-21 18:21 ` Luca Ceresoli
0 siblings, 0 replies; 8+ messages in thread
From: Luca Ceresoli @ 2025-03-21 18:21 UTC (permalink / raw)
To: Maxime Ripard
Cc: dri-devel, imx, linux-arm-kernel, linux-kernel, Andrzej Hajda,
Anusha Srivatsa, David Airlie, Dmitry Baryshkov, Fabio Estevam,
Hervé Codina, Hui Pu, Inki Dae, Jagan Teki, Jernej Skrabec,
Jonas Karlman, Laurent Pinchart, Maarten Lankhorst,
Marek Szyprowski, Marek Vasut, Neil Armstrong, Paul Kocialkowski,
Pengutronix Kernel Team, Robert Foss, Sascha Hauer, Shawn Guo,
Simona Vetter, Stefan Agner, Thomas Petazzoni, Thomas Zimmermann
Hello Maxime,
On Fri, 21 Mar 2025 09:54:55 +0000
"Maxime Ripard" <mripard@kernel.org> wrote:
> On Thu, 20 Mar 2025 16:42:11 +0100, Luca Ceresoli wrote:
> > 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
> >
> > [ ... ]
>
> Reviewed-by: Maxime Ripard <mripard@kernel.org>
Thanks a lot for reviewing!
I noticed you haven't replied on patch 3. Being a change you had
suggested, I was wondering whether haven't noticed that. If you are OK
with that patch, the entire series would have a R-by, which would be
great to unlock all the work depending on this series.
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-03-21 18:21 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-20 15:42 [PATCH v8 0/5] drm/bridge: add devm_drm_bridge_alloc() with bridge refcount Luca Ceresoli
2025-03-20 15:42 ` [PATCH v8 1/5] drm/bridge: add devm_drm_bridge_alloc() Luca Ceresoli
2025-03-20 15:42 ` [PATCH v8 2/5] drm/bridge: add support for refcounting Luca Ceresoli
2025-03-21 9:54 ` Maxime Ripard
2025-03-21 18:21 ` Luca Ceresoli
2025-03-20 15:42 ` [PATCH v8 3/5] drm/bridge: deprecate old-style bridge allocation Luca Ceresoli
2025-03-20 15:42 ` [PATCH v8 4/5] drm/bridge: ti-sn65dsi83: use dynamic lifetime management Luca Ceresoli
2025-03-20 15:42 ` [PATCH v8 5/5] drm/bridge: samsung-dsim: " Luca Ceresoli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).