[Intel-gfx] [PATCH] drm: remove mode from list and destroy it in order

Ma Ling ling.ma at intel.com
Fri Jun 5 11:15:44 CEST 2009


Usually We create drm mode by drm_mode_create function which also will assign ID
to this mode by drm_mode_object_get function, then insert this new mode into 
mode list by list_add function. So when destroying mode, we need to remove mode
from list, then free ID and allocated memory by drm_mode_destroy function,
otherwise memory leak.

Signed-off-by: Ma Ling <ling.ma at intel.com>
---
 drivers/gpu/drm/drm_crtc.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 94a7688..03a7b30 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -423,7 +423,6 @@ void drm_mode_remove(struct drm_connector *connector,
 		     struct drm_display_mode *mode)
 {
 	list_del(&mode->head);
-	kfree(mode);
 }
 EXPORT_SYMBOL(drm_mode_remove);
 
@@ -485,14 +484,20 @@ void drm_connector_cleanup(struct drm_connector *connector)
 	struct drm_device *dev = connector->dev;
 	struct drm_display_mode *mode, *t;
 
-	list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
+	list_for_each_entry_safe(mode, t, &connector->probed_modes, head) {
 		drm_mode_remove(connector, mode);
+		drm_mode_destroy(dev, mode);
+	}
 
-	list_for_each_entry_safe(mode, t, &connector->modes, head)
+	list_for_each_entry_safe(mode, t, &connector->modes, head) {
 		drm_mode_remove(connector, mode);
+		drm_mode_destroy(dev, mode);
+	}
 
-	list_for_each_entry_safe(mode, t, &connector->user_modes, head)
+	list_for_each_entry_safe(mode, t, &connector->user_modes, head) {
 		drm_mode_remove(connector, mode);
+		drm_mode_destroy(dev, mode);
+	}
 
 	mutex_lock(&dev->mode_config.mutex);
 	drm_mode_object_put(dev, &connector->base);
-- 
1.5.4.4






More information about the Intel-gfx mailing list