Skip to contentSkip to conversation

drm/connector: check if destroy function exist

PATCH RESEND In review Andreas Kemnade 3 participants 4 messages Jul 2 – Jul 29

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 drm/connector: check if destroy function exist

Connectors might have not resources needed to be manually freed. E.g. the drm_bridge_connector does not have such a callback.

Fixes c12907be57b1 ("drm/bridge-connector: switch to using drmm allocations")
---
 drivers/gpu/drm/drm_connector.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_connector.c +6 -2
index 47dc53c4a738..d2dfc6e8f7d0 100644
@@ -198,7 +198,9 @@ static void drm_connector_free(struct kref *kref)
 	struct drm_device *dev = connector->dev;
 
 	drm_mode_object_unregister(dev, &connector->base);
-	connector->funcs->destroy(connector);
+
+	if (connector->funcs->destroy)
+		connector->funcs->destroy(connector);
 }
 
 void drm_connector_free_work_fn(struct work_struct *work)
@@ -216,7 +218,9 @@ void drm_connector_free_work_fn(struct work_struct *work)
 
 	llist_for_each_entry_safe(connector, n, freed, free_node) {
 		drm_mode_object_unregister(dev, &connector->base);
-		connector->funcs->destroy(connector);
+
+		if (connector->funcs->destroy)
+			connector->funcs->destroy(connector);
 	}
 }
 
Signature · 1 line
2.47.3
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Manual invocation of funcs->destroy() causes a NULL pointer dereference on the error path in msm_hdmi_modeset_init. --

commit aa404d4746f85dae926593fae989fac53f064b44
Author: Andreas Kemnade <[email protected]>

drm/connector: check if destroy function exist

Connectors might have not resources needed to be manually freed. E.g. the drm_bridge_connector does not have such a callback.

drivers/gpu/drm/drm_connector.c static void drm_connector_free(struct kref *kref) · line 204

Quoted 13 lines
drivers/gpu/drm/drm_connector.c +3 -1
index 8b4baed060f3a..288d9d6c75a8d 100644
@@ -198,7 +198,9 @@ static void drm_connector_free(struct kref *kref)
 	struct drm_device *dev = connector->dev;
 
 	drm_mode_object_unregister(dev, &connector->base);
-	connector->funcs->destroy(connector);
+
+	if (connector->funcs->destroy)
+		connector->funcs->destroy(connector);
 }

[Severity: High]
This isn't a bug introduced by this patch, but could the same NULL pointer dereference happen in the error path of msm_hdmi_modeset_init() when it manually cleans up the connector?

If devm_request_irq() fails after the drm_bridge_connector is successfully initialized, it seems the failure path blindly calls the destroy callback:

drivers/gpu/drm/msm/hdmi/hdmi.c:msm_hdmi_modeset_init() {
	...
	hdmi->connector = drm_bridge_connector_init(hdmi->dev, encoder);
	if (IS_ERR(hdmi->connector)) {
		...
	}

	ret = devm_request_irq(dev->dev, hdmi->irq, ...);
	if (ret < 0) {
		DRM_DEV_ERROR(dev->dev, "failed to request IRQ%u: %d\n",
				hdmi->irq, ret);
		goto fail;
	}

	return 0;

fail:

	if (hdmi->connector) {
		hdmi->connector->funcs->destroy(hdmi->connector);
		hdmi->connector = NULL;
	}

	return ret;
}

Should this driver-specific cleanup path also be updated to check if funcs->destroy is present, similar to the fix applied here in drm_connector_free?

Quoted 2 lines
drivers/gpu/drm/drm_connector.c +0 -0
 void drm_connector_free_work_fn(struct work_struct *work)

[ ... ]

Quoted 10 lines
drivers/gpu/drm/drm_connector.c +3 -1
@@ -216,7 +218,9 @@ void drm_connector_free_work_fn(struct work_struct *work)
 
 	llist_for_each_entry_safe(connector, n, freed, free_node) {
 		drm_mode_object_unregister(dev, &connector->base);
-		connector->funcs->destroy(connector);
+
+		if (connector->funcs->destroy)
+			connector->funcs->destroy(connector);
 	}
 }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Andreas Kemnade

Hi

Am 02.07.26 um 21:14 schrieb Andreas Kemnade:

Quoted 4 lines

Connectors might have not resources needed to be manually freed. E.g. the drm_bridge_connector does not have such a callback.

Fixes c12907be57b1 ("drm/bridge-connector: switch to using drmm allocations")

This patch uses drmm_connector_init() for the cleanup, which is a mis-design IMHO.  Rather than calling drm_connector_cleanup(), it should call connector->funcs->destroy, which then points to drm_connector_cleanup. This would make the whole thing more useful and not require fixups (like this one) elsewhere in the code. Just just my 2cts.

Best regards
Thomas

Quoted 31 lines
---
  drivers/gpu/drm/drm_connector.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_connector.c +6 -2
index 47dc53c4a738..d2dfc6e8f7d0 100644
@@ -198,7 +198,9 @@ static void drm_connector_free(struct kref *kref)
  	struct drm_device *dev = connector->dev;
 
  	drm_mode_object_unregister(dev, &connector->base);
-	connector->funcs->destroy(connector);
+
+	if (connector->funcs->destroy)
+		connector->funcs->destroy(connector);
  }
 
  void drm_connector_free_work_fn(struct work_struct *work)
@@ -216,7 +218,9 @@ void drm_connector_free_work_fn(struct work_struct *work)
 
  	llist_for_each_entry_safe(connector, n, freed, free_node) {
  		drm_mode_object_unregister(dev, &connector->base);
-		connector->funcs->destroy(connector);
+
+		if (connector->funcs->destroy)
+			connector->funcs->destroy(connector);
  	}
  }
 
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
#3 lore raw
Quoted 6 lines · Thomas Zimmermann

Hi

Am 02.07.26 um 21:14 schrieb Andreas Kemnade:

Quoted 3 lines

Connectors might have not resources needed to be manually freed. E.g. the drm_bridge_connector does not have such a callback.

Quoted 8 lines
Quoted 1 line
Fixes c12907be57b1 ("drm/bridge-connector: switch to using drmm allocations")

This patch uses drmm_connector_init() for the cleanup, which is a mis-design IMHO.  Rather than calling drm_connector_cleanup(), it should call connector->funcs->destroy, which then points to drm_connector_cleanup. This would make the whole thing more useful and not require fixups (like this one) elsewhere in the code. Just just my 2cts.

That just sounds like a revert to me. But maybe I misunterstand your comment

Quoted 42 lines

Best regards
Thomas

Quoted 27 lines
---
  drivers/gpu/drm/drm_connector.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_connector.c +6 -2
index 47dc53c4a738..d2dfc6e8f7d0 100644
@@ -198,7 +198,9 @@ static void drm_connector_free(struct kref *kref)
  	struct drm_device *dev = connector->dev;
  	drm_mode_object_unregister(dev, &connector->base);
-	connector->funcs->destroy(connector);
+
+	if (connector->funcs->destroy)
+		connector->funcs->destroy(connector);
  }
  void drm_connector_free_work_fn(struct work_struct *work)
@@ -216,7 +218,9 @@ void drm_connector_free_work_fn(struct work_struct *work)
  	llist_for_each_entry_safe(connector, n, freed, free_node) {
  		drm_mode_object_unregister(dev, &connector->base);
-		connector->funcs->destroy(connector);
+
+		if (connector->funcs->destroy)
+			connector->funcs->destroy(connector);
  	}
  }
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)