Skip to contentSkip to conversation

GPU: drm_debugfs, check kmalloc retval

PATCH New Jiri Slaby 1 participant 2 messages Jul 13, 2009

Subsystems (2)
lore
Share & tools
lore

Jiri Slaby

author
#0 lore raw

PATCH 1/2 GPU: drm_debugfs, check kmalloc retval

Check kmalloc return value in drm_debugfs_create_files and bail out appropriately if the pointer is NULL.

---
 drivers/gpu/drm/drm_debugfs.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
drivers/gpu/drm/drm_debugfs.c +4 -0
index 2960b6d..9903f27 100644
@@ -101,6 +101,10 @@ int drm_debugfs_create_files(struct drm_info_list *files, int count,
 			continue;
 
 		tmp = kmalloc(sizeof(struct drm_info_node), GFP_KERNEL);
+		if (tmp == NULL) {
+			ret = -1;
+			goto fail;
+		}
 		ent = debugfs_create_file(files[i].name, S_IFREG | S_IRUGO,
 					  root, tmp, &drm_debugfs_fops);
 		if (!ent) {
Signature · 1 line
1.6.3.2
author
#1 lore raw

PATCH 2/2 GPU: drm_gem, check kzalloc retval

Check kzalloc retval against NULL in drm_gem_object_alloc and bail out appropriately.

While at it merge the fail paths and jump to them by gotos at the end of the function.

---
 drivers/gpu/drm/drm_gem.c |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)
drivers/gpu/drm/drm_gem.c +10 -7
index 8104eca..ffe8f43 100644
@@ -134,26 +134,29 @@ drm_gem_object_alloc(struct drm_device *dev, size_t size)
 	BUG_ON((size & (PAGE_SIZE - 1)) != 0);
 
 	obj = kzalloc(sizeof(*obj), GFP_KERNEL);
+	if (!obj)
+		goto free;
 
 	obj->dev = dev;
 	obj->filp = shmem_file_setup("drm mm object", size, VM_NORESERVE);
-	if (IS_ERR(obj->filp)) {
-		kfree(obj);
-		return NULL;
-	}
+	if (IS_ERR(obj->filp))
+		goto free;
 
 	kref_init(&obj->refcount);
 	kref_init(&obj->handlecount);
 	obj->size = size;
 	if (dev->driver->gem_init_object != NULL &&
 	    dev->driver->gem_init_object(obj) != 0) {
-		fput(obj->filp);
-		kfree(obj);
-		return NULL;
+		goto fput;
 	}
 	atomic_inc(&dev->object_count);
 	atomic_add(obj->size, &dev->object_memory);
 	return obj;
+fput:
+	fput(obj->filp);
+free:
+	kfree(obj);
+	return NULL;
 }
 EXPORT_SYMBOL(drm_gem_object_alloc);
 
Signature · 1 line
1.6.3.2