drm/ttm: Fixes for "Memory accounting rework."

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linux Kernel Mailing List
Date: Monday, September 21, 2009 - 8:59 am

Gitweb:     http://git.kernel.org/linus/759e4f83f418f4001e724042b4c0e408d615d9ec
Commit:     759e4f83f418f4001e724042b4c0e408d615d9ec
Parent:     7f5f4db2d50ea1af8f160686d2e97bbfa5102b4f
Author:     Thomas Hellstrom <thellstrom@vmware.com>
AuthorDate: Thu Aug 20 10:29:09 2009 +0200
Committer:  Dave Airlie <airlied@redhat.com>
CommitDate: Thu Aug 20 18:58:15 2009 +1000

    drm/ttm: Fixes for "Memory accounting rework."
    
    ttm:
    Fix error paths when kobject_add returns an error.
    
    Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
    Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/ttm/ttm_memory.c |   36 ++++++++++++++++++++++++++++--------
 1 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
index 62fb5cf..072c281 100644
--- a/drivers/gpu/drm/ttm/ttm_memory.c
+++ b/drivers/gpu/drm/ttm/ttm_memory.c
@@ -244,6 +244,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
 {
 	struct ttm_mem_zone *zone = kzalloc(sizeof(*zone), GFP_KERNEL);
 	uint64_t mem;
+	int ret;
 
 	if (unlikely(!zone))
 		return -ENOMEM;
@@ -259,9 +260,14 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
 	zone->used_mem = 0;
 	zone->glob = glob;
 	glob->zone_kernel = zone;
-	glob->zones[glob->num_zones++] = zone;
 	kobject_init(&zone->kobj, &ttm_mem_zone_kobj_type);
-	return kobject_add(&zone->kobj, &glob->kobj, zone->name);
+	ret = kobject_add(&zone->kobj, &glob->kobj, zone->name);
+	if (unlikely(ret != 0)) {
+		kobject_put(&zone->kobj);
+		return ret;
+	}
+	glob->zones[glob->num_zones++] = zone;
+	return 0;
 }
 
 #ifdef CONFIG_HIGHMEM
@@ -270,6 +276,7 @@ static int ttm_mem_init_highmem_zone(struct ttm_mem_global *glob,
 {
 	struct ttm_mem_zone *zone = kzalloc(sizeof(*zone), GFP_KERNEL);
 	uint64_t mem;
+	int ret;
 
 	if (unlikely(!zone))
 		return -ENOMEM;
@@ -288,9 +295,14 @@ static int ttm_mem_init_highmem_zone(struct ttm_mem_global *glob,
 	zone->used_mem = 0;
 	zone->glob = glob;
 	glob->zone_highmem = zone;
-	glob->zones[glob->num_zones++] = zone;
 	kobject_init(&zone->kobj, &ttm_mem_zone_kobj_type);
-	return kobject_add(&zone->kobj, &glob->kobj, zone->name);
+	ret = kobject_add(&zone->kobj, &glob->kobj, zone->name);
+	if (unlikely(ret != 0)) {
+		kobject_put(&zone->kobj);
+		return ret;
+	}
+	glob->zones[glob->num_zones++] = zone;
+	return 0;
 }
 #else
 static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
@@ -298,6 +310,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
 {
 	struct ttm_mem_zone *zone = kzalloc(sizeof(*zone), GFP_KERNEL);
 	uint64_t mem;
+	int ret;
 
 	if (unlikely(!zone))
 		return -ENOMEM;
@@ -327,9 +340,14 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
 	zone->used_mem = 0;
 	zone->glob = glob;
 	glob->zone_dma32 = zone;
-	glob->zones[glob->num_zones++] = zone;
 	kobject_init(&zone->kobj, &ttm_mem_zone_kobj_type);
-	return kobject_add(&zone->kobj, &glob->kobj, zone->name);
+	ret = kobject_add(&zone->kobj, &glob->kobj, zone->name);
+	if (unlikely(ret != 0)) {
+		kobject_put(&zone->kobj);
+		return ret;
+	}
+	glob->zones[glob->num_zones++] = zone;
+	return 0;
 }
 #endif
 
@@ -348,8 +366,10 @@ int ttm_mem_global_init(struct ttm_mem_global *glob)
 	ret = kobject_add(&glob->kobj,
 			  ttm_get_kobj(),
 			  "memory_accounting");
-	if (unlikely(ret != 0))
-		goto out_no_zone;
+	if (unlikely(ret != 0)) {
+		kobject_put(&glob->kobj);
+		return ret;
+	}
 
 	si_meminfo(&si);
 
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
drm/ttm: Fixes for "Memory accounting rework.", Linux Kernel Mailing ..., (Mon Sep 21, 8:59 am)