Some code is going to need connector-specific cleanup actions (namely
drm_bridge_connector will need to put refcounted bridges).
The .destroy callback is appropriate for this task but it is currently
forbidden by drmm_connector_init(). Relax this limitation and document it.
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
---
The other obvious approach would be adding a separate .cleanup callback for
the cleanup-only actions. I tried both, they both apparently work, so any
arguments and opinions on which approach is best within the overall DRM
design would be very useful here.
---
drivers/gpu/drm/drm_connector.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
index 272d6254ea4784e97ca894ec4d463beebf9fdbf0..bd0220513a23afcb096b0c4c4d2b957b81f21ee1 100644
--- a/drivers/gpu/drm/drm_connector.c
+++ b/drivers/gpu/drm/drm_connector.c
@@ -513,7 +513,8 @@ static void drm_connector_cleanup_action(struct drm_device *dev,
*
* The connector structure should be allocated with drmm_kzalloc().
*
- * The @drm_connector_funcs.destroy hook must be NULL.
+ * The @drm_connector_funcs.destroy hook must only do connector-specific
+ * cleanups if any is needed, not dealloacte the connector.
*
* Returns:
* Zero on success, error code on failure.
@@ -526,9 +527,6 @@ int drmm_connector_init(struct drm_device *dev,
{
int ret;
- if (drm_WARN_ON(dev, funcs && funcs->destroy))
- return -EINVAL;
-
ret = drm_connector_init_and_add(dev, connector, funcs, connector_type, ddc);
if (ret)
return ret;
--
2.51.0
On Thu, 25 Sep 2025, Luca Ceresoli <luca.ceresoli@bootlin.com> wrote: > Some code is going to need connector-specific cleanup actions (namely > drm_bridge_connector will need to put refcounted bridges). > > The .destroy callback is appropriate for this task but it is currently > forbidden by drmm_connector_init(). Relax this limitation and document it. > > Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com> > > --- > > The other obvious approach would be adding a separate .cleanup callback for > the cleanup-only actions. I tried both, they both apparently work, so any > arguments and opinions on which approach is best within the overall DRM > design would be very useful here. > --- > drivers/gpu/drm/drm_connector.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c > index 272d6254ea4784e97ca894ec4d463beebf9fdbf0..bd0220513a23afcb096b0c4c4d2b957b81f21ee1 100644 > --- a/drivers/gpu/drm/drm_connector.c > +++ b/drivers/gpu/drm/drm_connector.c > @@ -513,7 +513,8 @@ static void drm_connector_cleanup_action(struct drm_device *dev, > * > * The connector structure should be allocated with drmm_kzalloc(). > * > - * The @drm_connector_funcs.destroy hook must be NULL. > + * The @drm_connector_funcs.destroy hook must only do connector-specific > + * cleanups if any is needed, not dealloacte the connector. It slightly feels like a trap to have different semantics for ->destroy depending on how the connector was allocated. BR, Jani. > * > * Returns: > * Zero on success, error code on failure. > @@ -526,9 +527,6 @@ int drmm_connector_init(struct drm_device *dev, > { > int ret; > > - if (drm_WARN_ON(dev, funcs && funcs->destroy)) > - return -EINVAL; > - > ret = drm_connector_init_and_add(dev, connector, funcs, connector_type, ddc); > if (ret) > return ret; -- Jani Nikula, Intel
On Thu, Sep 25, 2025 at 07:19:49PM +0200, Luca Ceresoli wrote: > Some code is going to need connector-specific cleanup actions (namely > drm_bridge_connector will need to put refcounted bridges). > > The .destroy callback is appropriate for this task but it is currently > forbidden by drmm_connector_init(). Relax this limitation and document it. > > Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com> > > --- > > The other obvious approach would be adding a separate .cleanup callback for > the cleanup-only actions. I tried both, they both apparently work, so any > arguments and opinions on which approach is best within the overall DRM > design would be very useful here. Would it be better to use drmm-reset actions. I think the check here makes much more help overall than harm in your case, so I'd suggest leaving it in place. > --- > drivers/gpu/drm/drm_connector.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c > index 272d6254ea4784e97ca894ec4d463beebf9fdbf0..bd0220513a23afcb096b0c4c4d2b957b81f21ee1 100644 > --- a/drivers/gpu/drm/drm_connector.c > +++ b/drivers/gpu/drm/drm_connector.c > @@ -513,7 +513,8 @@ static void drm_connector_cleanup_action(struct drm_device *dev, > * > * The connector structure should be allocated with drmm_kzalloc(). > * > - * The @drm_connector_funcs.destroy hook must be NULL. > + * The @drm_connector_funcs.destroy hook must only do connector-specific > + * cleanups if any is needed, not dealloacte the connector. > * > * Returns: > * Zero on success, error code on failure. > @@ -526,9 +527,6 @@ int drmm_connector_init(struct drm_device *dev, > { > int ret; > > - if (drm_WARN_ON(dev, funcs && funcs->destroy)) > - return -EINVAL; > - > ret = drm_connector_init_and_add(dev, connector, funcs, connector_type, ddc); > if (ret) > return ret; > > -- > 2.51.0 > -- With best wishes Dmitry
Hi Dmitry, On Fri, 26 Sep 2025 01:07:26 +0300 Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com> wrote: > On Thu, Sep 25, 2025 at 07:19:49PM +0200, Luca Ceresoli wrote: > > Some code is going to need connector-specific cleanup actions (namely > > drm_bridge_connector will need to put refcounted bridges). > > > > The .destroy callback is appropriate for this task but it is currently > > forbidden by drmm_connector_init(). Relax this limitation and document it. > > > > Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com> > > > > --- > > > > The other obvious approach would be adding a separate .cleanup callback for > > the cleanup-only actions. I tried both, they both apparently work, so any > > arguments and opinions on which approach is best within the overall DRM > > design would be very useful here. > > Would it be better to use drmm-reset actions. I think the check here > makes much more help overall than harm in your case, so I'd suggest > leaving it in place. Thanks for the feedback! I think using drmm_add_action[_or_reset]() here makes sense indeed. As I understand it, both .destroy and drmm_add_action[_or_reset]() actions will trigger when the drm_device is removed. This is not ideal for hotplugging because one would add/remove bridges while the drm_device is persistent, so on multiple hot plug/unplug loops stale resources would accumulate until the final card removal, perhaps at system shutdown. However for now my goal is to have bridges refcount in place to avoid use-after-free. Releasing resources for hot-unplugged bridges for this case is a further step. Bottom line: same drawback for both solutions, but the drmm action is cleaner. v2 incoming with a drmm action. Best regards, Luca -- Luca Ceresoli, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
© 2016 - 2025 Red Hat, Inc.