Skip to contentSkip to conversation

drm/nouveau: fix error handling in core/core object creation functions

PATCH In review Marcin Slusarz 2 participants 5 messages Oct 7, 2012 – Oct 9, 2012 3 messages not in the archive

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

PATCH 1/1 drm/nouveau: fix error handling in core/core object creation functions

---
This patch relies on "drm/nouveau: remove >1 sclass support from nouveau_parent_create_".

There are *many* *more* code paths without proper error handling - I counted at least 106 in 41 functions. If someone would like to do a bit of janitorial work I marked those code paths and uploaded "patch" here:
http://people.freedesktop.org/~mslusarz/0001-codepaths-without-error-handling.patch
(Please let me know if you are going to fix those to not duplicate work)

---
 drivers/gpu/drm/nouveau/core/core/engine.c | 1 +
 drivers/gpu/drm/nouveau/core/core/gpuobj.c | 9 ++++++---
 drivers/gpu/drm/nouveau/core/core/parent.c | 4 +++-
 3 files changed, 10 insertions(+), 4 deletions(-)
drivers/gpu/drm/nouveau/core/core/engine.c +1 -0
index 09b3bd5..4319854 100644
@@ -44,6 +44,7 @@ nouveau_engine_create_(struct nouveau_object *parent,
 		return ret;
 
 	if (!nouveau_boolopt(device->cfgopt, iname, enable)) {
+		nouveau_subdev_destroy(&engine->base);
 		if (!enable)
 			nv_warn(engine, "disabled, %s=1 to enable\n", iname);
 		return -ENODEV;
drivers/gpu/drm/nouveau/core/core/gpuobj.c +6 -3
index c2a7608..6254d52 100644
@@ -40,7 +40,7 @@ nouveau_gpuobj_destroy(struct nouveau_gpuobj *gpuobj)
 	}
 
 	if (gpuobj->heap.block_size)
-		nouveau_mm_fini(&gpuobj->heap);
+		WARN_ON(nouveau_mm_fini(&gpuobj->heap));
 
 	nouveau_object_destroy(&gpuobj->base);
 }
@@ -113,7 +113,7 @@ nouveau_gpuobj_create_(struct nouveau_object *parent,
 		ret = nouveau_mm_head(heap, 1, size, size,
 				      max(align, (u32)1), &gpuobj->node);
 		if (ret)
-			return ret;
+			goto err;
 
 		gpuobj->addr += gpuobj->node->offset;
 	}
@@ -121,7 +121,7 @@ nouveau_gpuobj_create_(struct nouveau_object *parent,
 	if (gpuobj->flags & NVOBJ_FLAG_HEAP) {
 		ret = nouveau_mm_init(&gpuobj->heap, 0, gpuobj->size, 1);
 		if (ret)
-			return ret;
+			goto err;
 	}
 
 	if (flags & NVOBJ_FLAG_ZERO_ALLOC) {
@@ -130,6 +130,9 @@ nouveau_gpuobj_create_(struct nouveau_object *parent,
 	}
 
 	return ret;
+err:
+	nouveau_gpuobj_destroy(gpuobj);
+	return ret;
 }
 
 struct nouveau_gpuobj_class {
drivers/gpu/drm/nouveau/core/core/parent.c +3 -1
index 1a48e58..d2ea7c2 100644
@@ -87,8 +87,10 @@ nouveau_parent_create_(struct nouveau_object *parent,
 
 	if (sclass && sclass->ofuncs) {
 		nclass = kzalloc(sizeof(*nclass), GFP_KERNEL);
-		if (!nclass)
+		if (!nclass) {
+			nouveau_parent_destroy(object);
 			return -ENOMEM;
+		}
 
 		nclass->sclass = object->sclass;
 		object->sclass = nclass;
Signature · 1 line
1.7.12

A message that is not in the archive (sent off-list or not yet received): 1349650171-25045-5-git-send-email-marcin.slusarz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw
Quoted 32 lines · Marcin Slusarz

---
This patch relies on "drm/nouveau: remove >1 sclass support from nouveau_parent_create_".

There are *many* *more* code paths without proper error handling - I counted at least 106 in 41 functions. If someone would like to do a bit of janitorial work I marked those code paths and uploaded "patch" here:
http://people.freedesktop.org/~mslusarz/0001-codepaths-without-error-handling.patch
(Please let me know if you are going to fix those to not duplicate work)

---
 drivers/gpu/drm/nouveau/core/core/engine.c | 1 +
 drivers/gpu/drm/nouveau/core/core/gpuobj.c | 9 ++++++---
 drivers/gpu/drm/nouveau/core/core/parent.c | 4 +++-
 3 files changed, 10 insertions(+), 4 deletions(-)
drivers/gpu/drm/nouveau/core/core/engine.c +1 -0
index 09b3bd5..4319854 100644
@@ -44,6 +44,7 @@ nouveau_engine_create_(struct nouveau_object *parent,
 		return ret;
 
 	if (!nouveau_boolopt(device->cfgopt, iname, enable)) {
+		nouveau_subdev_destroy(&engine->base);
 		if (!enable)
 			nv_warn(engine, "disabled, %s=1 to enable\n", iname);
 		return -ENODEV;
drivers/gpu/drm/nouveau/core/core/gpuobj.c +0 -0
index c2a7608..6254d52 100644

drivers/gpu/drm/nouveau/core/core/gpuobj.c nouveau_gpuobj_destroy(struct nouveau_gpuobj *gpuobj) · line 43

Quoted 5 lines
drivers/gpu/drm/nouveau/core/core/gpuobj.c +1 -1
@@ -40,7 +40,7 @@ nouveau_gpuobj_destroy(struct nouveau_gpuobj *gpuobj)
 	}
 
 	if (gpuobj->heap.block_size)
-		nouveau_mm_fini(&gpuobj->heap);
+		WARN_ON(nouveau_mm_fini(&gpuobj->heap));

Ha! This is triggering on channel close. Maybe it's the leak which is preventing piglit from finishing...

Quoted 50 lines
drivers/gpu/drm/nouveau/core/core/gpuobj.c +5 -2
 	nouveau_object_destroy(&gpuobj->base);
 }
@@ -113,7 +113,7 @@ nouveau_gpuobj_create_(struct nouveau_object *parent,
 		ret = nouveau_mm_head(heap, 1, size, size,
 				      max(align, (u32)1), &gpuobj->node);
 		if (ret)
-			return ret;
+			goto err;
 
 		gpuobj->addr += gpuobj->node->offset;
 	}
@@ -121,7 +121,7 @@ nouveau_gpuobj_create_(struct nouveau_object *parent,
 	if (gpuobj->flags & NVOBJ_FLAG_HEAP) {
 		ret = nouveau_mm_init(&gpuobj->heap, 0, gpuobj->size, 1);
 		if (ret)
-			return ret;
+			goto err;
 	}
 
 	if (flags & NVOBJ_FLAG_ZERO_ALLOC) {
@@ -130,6 +130,9 @@ nouveau_gpuobj_create_(struct nouveau_object *parent,
 	}
 
 	return ret;
+err:
+	nouveau_gpuobj_destroy(gpuobj);
+	return ret;
 }
 
 struct nouveau_gpuobj_class {
drivers/gpu/drm/nouveau/core/core/parent.c +3 -1
index 1a48e58..d2ea7c2 100644
@@ -87,8 +87,10 @@ nouveau_parent_create_(struct nouveau_object *parent,
 
 	if (sclass && sclass->ofuncs) {
 		nclass = kzalloc(sizeof(*nclass), GFP_KERNEL);
-		if (!nclass)
+		if (!nclass) {
+			nouveau_parent_destroy(object);
 			return -ENOMEM;
+		}
 
 		nclass->sclass = object->sclass;
 		object->sclass = nclass;
Signature · 1 line
1.7.12
#3 lore raw
In reply to a message not in the archive
Quoted 5 lines · Marcin Slusarz

---
This patch relies on "drm/nouveau: remove >1 sclass support from nouveau_parent_create_".

There are *many* *more* code paths without proper error handling -

This is *not* a bug. An object's constructor should be called via nouveau_object_ctor(), which has the semantics that the constructor returns and error *and* a pointer returned via pobject, then the class's destructor will be called to cleanup.

Ben.

Quoted 87 lines

I counted
at least 106 in 41 functions. If someone would like to do a bit of janitorial work I marked those code paths and uploaded "patch" here:
http://people.freedesktop.org/~mslusarz/0001-codepaths-without-error-handling.patch
(Please let me know if you are going to fix those to not duplicate work)

---
 drivers/gpu/drm/nouveau/core/core/engine.c | 1 +
 drivers/gpu/drm/nouveau/core/core/gpuobj.c | 9 ++++++---
 drivers/gpu/drm/nouveau/core/core/parent.c | 4 +++-
 3 files changed, 10 insertions(+), 4 deletions(-)
drivers/gpu/drm/nouveau/core/core/engine.c +1 -0
index 09b3bd5..4319854 100644
@@ -44,6 +44,7 @@ nouveau_engine_create_(struct nouveau_object *parent,
 		return ret;
 
 	if (!nouveau_boolopt(device->cfgopt, iname, enable)) {
+		nouveau_subdev_destroy(&engine->base);
 		if (!enable)
 			nv_warn(engine, "disabled, %s=1 to enable\n", iname);
 		return -ENODEV;
drivers/gpu/drm/nouveau/core/core/gpuobj.c +6 -3
index c2a7608..6254d52 100644
@@ -40,7 +40,7 @@ nouveau_gpuobj_destroy(struct nouveau_gpuobj *gpuobj)
 	}
 
 	if (gpuobj->heap.block_size)
-		nouveau_mm_fini(&gpuobj->heap);
+		WARN_ON(nouveau_mm_fini(&gpuobj->heap));
 
 	nouveau_object_destroy(&gpuobj->base);
 }
@@ -113,7 +113,7 @@ nouveau_gpuobj_create_(struct nouveau_object *parent,
 		ret = nouveau_mm_head(heap, 1, size, size,
 				      max(align, (u32)1), &gpuobj->node);
 		if (ret)
-			return ret;
+			goto err;
 
 		gpuobj->addr += gpuobj->node->offset;
 	}
@@ -121,7 +121,7 @@ nouveau_gpuobj_create_(struct nouveau_object *parent,
 	if (gpuobj->flags & NVOBJ_FLAG_HEAP) {
 		ret = nouveau_mm_init(&gpuobj->heap, 0, gpuobj->size, 1);
 		if (ret)
-			return ret;
+			goto err;
 	}
 
 	if (flags & NVOBJ_FLAG_ZERO_ALLOC) {
@@ -130,6 +130,9 @@ nouveau_gpuobj_create_(struct nouveau_object *parent,
 	}
 
 	return ret;
+err:
+	nouveau_gpuobj_destroy(gpuobj);
+	return ret;
 }
 
 struct nouveau_gpuobj_class {
drivers/gpu/drm/nouveau/core/core/parent.c +3 -1
index 1a48e58..d2ea7c2 100644
@@ -87,8 +87,10 @@ nouveau_parent_create_(struct nouveau_object *parent,
 
 	if (sclass && sclass->ofuncs) {
 		nclass = kzalloc(sizeof(*nclass), GFP_KERNEL);
-		if (!nclass)
+		if (!nclass) {
+			nouveau_parent_destroy(object);
 			return -ENOMEM;
+		}
 
 		nclass->sclass = object->sclass;
 		object->sclass = nclass;
Signature · 6 lines
1.7.12

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

A message that is not in the archive (sent off-list or not yet received): 20121008010533.GA4197-6RkuLLNOGXsZ315U/[email protected]

#5 lore raw
Quoted 10 lines · Ben Skeggs
Quoted 5 lines · Marcin Slusarz

---
This patch relies on "drm/nouveau: remove >1 sclass support from nouveau_parent_create_".

There are *many* *more* code paths without proper error handling -

This is *not* a bug. An object's constructor should be called via nouveau_object_ctor(), which has the semantics that the constructor returns and error *and* a pointer returned via pobject, then the class's destructor will be called to cleanup.

That's... clever, and crazy, and unlike anything in kernel land...

Please put a comment near ctor field in nouveau_ofuncs to make this information easier to discover, without need to review the whole call chain...

Marcin

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw
Quoted 6 lines · Marcin Slusarz
Quoted 5 lines · Ben Skeggs
Quoted 4 lines · Marcin Slusarz

---
This patch relies on "drm/nouveau: remove >1 sclass support from nouveau_parent_create_".

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

There are *many* *more* code paths without proper error handling -

This is *not* a bug. An object's constructor should be called via nouveau_object_ctor(), which has the semantics that the constructor returns and error *and* a pointer returned via pobject, then the class's destructor will be called to cleanup.

That's... clever, and crazy, and unlike anything in kernel land...

Yep, I know. It made sense to me, rather than having two copies of the destructor code, one of them filled with gotos :)

Quoted 3 lines

Please put a comment near ctor field in nouveau_ofuncs to make this information easier to discover, without need to review the whole call chain...

Alright, I'll do something to that effect. I have been adding comments as I go to some WIP stuff I have going on too.

Ben.

Quoted 2 lines

Marcin