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>
This commit is contained in:
parent
d25e3a6faa
commit
845792d940
@ -134,26 +134,29 @@ drm_gem_object_alloc(struct drm_device *dev, size_t size)
|
|||||||
BUG_ON((size & (PAGE_SIZE - 1)) != 0);
|
BUG_ON((size & (PAGE_SIZE - 1)) != 0);
|
||||||
|
|
||||||
obj = kzalloc(sizeof(*obj), GFP_KERNEL);
|
obj = kzalloc(sizeof(*obj), GFP_KERNEL);
|
||||||
|
if (!obj)
|
||||||
|
goto free;
|
||||||
|
|
||||||
obj->dev = dev;
|
obj->dev = dev;
|
||||||
obj->filp = shmem_file_setup("drm mm object", size, VM_NORESERVE);
|
obj->filp = shmem_file_setup("drm mm object", size, VM_NORESERVE);
|
||||||
if (IS_ERR(obj->filp)) {
|
if (IS_ERR(obj->filp))
|
||||||
kfree(obj);
|
goto free;
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
kref_init(&obj->refcount);
|
kref_init(&obj->refcount);
|
||||||
kref_init(&obj->handlecount);
|
kref_init(&obj->handlecount);
|
||||||
obj->size = size;
|
obj->size = size;
|
||||||
if (dev->driver->gem_init_object != NULL &&
|
if (dev->driver->gem_init_object != NULL &&
|
||||||
dev->driver->gem_init_object(obj) != 0) {
|
dev->driver->gem_init_object(obj) != 0) {
|
||||||
fput(obj->filp);
|
goto fput;
|
||||||
kfree(obj);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
atomic_inc(&dev->object_count);
|
atomic_inc(&dev->object_count);
|
||||||
atomic_add(obj->size, &dev->object_memory);
|
atomic_add(obj->size, &dev->object_memory);
|
||||||
return obj;
|
return obj;
|
||||||
|
fput:
|
||||||
|
fput(obj->filp);
|
||||||
|
free:
|
||||||
|
kfree(obj);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(drm_gem_object_alloc);
|
EXPORT_SYMBOL(drm_gem_object_alloc);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user