aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/drm_gem.c
diff options
context:
space:
mode:
authorJiri Slaby <jirislaby@gmail.com>2009-07-13 17:20:21 -0400
committerDave Airlie <airlied@linux.ie>2009-07-15 01:56:12 -0400
commit845792d940f5755b7a7837c450a71d9e831a13e2 (patch)
tree92b4aee24f19c6522e17e2b2b026ea1128389c93 /drivers/gpu/drm/drm_gem.c
parentd25e3a6faa82eeaa6e5487c2d2e27cfd938ed108 (diff)
drm: 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. Signed-off-by: Jiri Slaby <jirislaby@gmail.com> Signed-off-by: Dave Airlie <airlied@linux.ie>
Diffstat (limited to 'drivers/gpu/drm/drm_gem.c')
-rw-r--r--drivers/gpu/drm/drm_gem.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index 8104ecaea26f..ffe8f4394d50 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -134,26 +134,29 @@ drm_gem_object_alloc(struct drm_device *dev, size_t size)
134 BUG_ON((size & (PAGE_SIZE - 1)) != 0); 134 BUG_ON((size & (PAGE_SIZE - 1)) != 0);
135 135
136 obj = kzalloc(sizeof(*obj), GFP_KERNEL); 136 obj = kzalloc(sizeof(*obj), GFP_KERNEL);
137 if (!obj)
138 goto free;
137 139
138 obj->dev = dev; 140 obj->dev = dev;
139 obj->filp = shmem_file_setup("drm mm object", size, VM_NORESERVE); 141 obj->filp = shmem_file_setup("drm mm object", size, VM_NORESERVE);
140 if (IS_ERR(obj->filp)) { 142 if (IS_ERR(obj->filp))
141 kfree(obj); 143 goto free;
142 return NULL;
143 }
144 144
145 kref_init(&obj->refcount); 145 kref_init(&obj->refcount);
146 kref_init(&obj->handlecount); 146 kref_init(&obj->handlecount);
147 obj->size = size; 147 obj->size = size;
148 if (dev->driver->gem_init_object != NULL && 148 if (dev->driver->gem_init_object != NULL &&
149 dev->driver->gem_init_object(obj) != 0) { 149 dev->driver->gem_init_object(obj) != 0) {
150 fput(obj->filp); 150 goto fput;
151 kfree(obj);
152 return NULL;
153 } 151 }
154 atomic_inc(&dev->object_count); 152 atomic_inc(&dev->object_count);
155 atomic_add(obj->size, &dev->object_memory); 153 atomic_add(obj->size, &dev->object_memory);
156 return obj; 154 return obj;
155fput:
156 fput(obj->filp);
157free:
158 kfree(obj);
159 return NULL;
157} 160}
158EXPORT_SYMBOL(drm_gem_object_alloc); 161EXPORT_SYMBOL(drm_gem_object_alloc);
159 162