Commit 94e3370e authored by Davidlohr Bueso's avatar Davidlohr Bueso Committed by Dave Airlie

DRM: Replace kmalloc/memset combos with kzalloc

Currently most, if not all, memory allocation in drm_bufs.c is followed by initializing the memory with 0.

Replace the use of kmalloc+memset with kzalloc.
Signed-off-by: default avatarDavidlohr Bueso <dave@gnu.org>
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent 7203425a
...@@ -328,14 +328,13 @@ static int drm_addmap_core(struct drm_device * dev, resource_size_t offset, ...@@ -328,14 +328,13 @@ static int drm_addmap_core(struct drm_device * dev, resource_size_t offset,
return -EINVAL; return -EINVAL;
} }
list = kmalloc(sizeof(*list), GFP_KERNEL); list = kzalloc(sizeof(*list), GFP_KERNEL);
if (!list) { if (!list) {
if (map->type == _DRM_REGISTERS) if (map->type == _DRM_REGISTERS)
iounmap(map->handle); iounmap(map->handle);
kfree(map); kfree(map);
return -EINVAL; return -EINVAL;
} }
memset(list, 0, sizeof(*list));
list->map = map; list->map = map;
mutex_lock(&dev->struct_mutex); mutex_lock(&dev->struct_mutex);
...@@ -678,13 +677,12 @@ int drm_addbufs_agp(struct drm_device * dev, struct drm_buf_desc * request) ...@@ -678,13 +677,12 @@ int drm_addbufs_agp(struct drm_device * dev, struct drm_buf_desc * request)
return -EINVAL; return -EINVAL;
} }
entry->buflist = kmalloc(count * sizeof(*entry->buflist), GFP_KERNEL); entry->buflist = kzalloc(count * sizeof(*entry->buflist), GFP_KERNEL);
if (!entry->buflist) { if (!entry->buflist) {
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
atomic_dec(&dev->buf_alloc); atomic_dec(&dev->buf_alloc);
return -ENOMEM; return -ENOMEM;
} }
memset(entry->buflist, 0, count * sizeof(*entry->buflist));
entry->buf_size = size; entry->buf_size = size;
entry->page_order = page_order; entry->page_order = page_order;
...@@ -708,7 +706,7 @@ int drm_addbufs_agp(struct drm_device * dev, struct drm_buf_desc * request) ...@@ -708,7 +706,7 @@ int drm_addbufs_agp(struct drm_device * dev, struct drm_buf_desc * request)
buf->file_priv = NULL; buf->file_priv = NULL;
buf->dev_priv_size = dev->driver->dev_priv_size; buf->dev_priv_size = dev->driver->dev_priv_size;
buf->dev_private = kmalloc(buf->dev_priv_size, GFP_KERNEL); buf->dev_private = kzalloc(buf->dev_priv_size, GFP_KERNEL);
if (!buf->dev_private) { if (!buf->dev_private) {
/* Set count correctly so we free the proper amount. */ /* Set count correctly so we free the proper amount. */
entry->buf_count = count; entry->buf_count = count;
...@@ -717,7 +715,6 @@ int drm_addbufs_agp(struct drm_device * dev, struct drm_buf_desc * request) ...@@ -717,7 +715,6 @@ int drm_addbufs_agp(struct drm_device * dev, struct drm_buf_desc * request)
atomic_dec(&dev->buf_alloc); atomic_dec(&dev->buf_alloc);
return -ENOMEM; return -ENOMEM;
} }
memset(buf->dev_private, 0, buf->dev_priv_size);
DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address); DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address);
...@@ -832,22 +829,20 @@ int drm_addbufs_pci(struct drm_device * dev, struct drm_buf_desc * request) ...@@ -832,22 +829,20 @@ int drm_addbufs_pci(struct drm_device * dev, struct drm_buf_desc * request)
return -EINVAL; return -EINVAL;
} }
entry->buflist = kmalloc(count * sizeof(*entry->buflist), GFP_KERNEL); entry->buflist = kzalloc(count * sizeof(*entry->buflist), GFP_KERNEL);
if (!entry->buflist) { if (!entry->buflist) {
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
atomic_dec(&dev->buf_alloc); atomic_dec(&dev->buf_alloc);
return -ENOMEM; return -ENOMEM;
} }
memset(entry->buflist, 0, count * sizeof(*entry->buflist));
entry->seglist = kmalloc(count * sizeof(*entry->seglist), GFP_KERNEL); entry->seglist = kzalloc(count * sizeof(*entry->seglist), GFP_KERNEL);
if (!entry->seglist) { if (!entry->seglist) {
kfree(entry->buflist); kfree(entry->buflist);
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
atomic_dec(&dev->buf_alloc); atomic_dec(&dev->buf_alloc);
return -ENOMEM; return -ENOMEM;
} }
memset(entry->seglist, 0, count * sizeof(*entry->seglist));
/* Keep the original pagelist until we know all the allocations /* Keep the original pagelist until we know all the allocations
* have succeeded * have succeeded
...@@ -911,7 +906,7 @@ int drm_addbufs_pci(struct drm_device * dev, struct drm_buf_desc * request) ...@@ -911,7 +906,7 @@ int drm_addbufs_pci(struct drm_device * dev, struct drm_buf_desc * request)
buf->file_priv = NULL; buf->file_priv = NULL;
buf->dev_priv_size = dev->driver->dev_priv_size; buf->dev_priv_size = dev->driver->dev_priv_size;
buf->dev_private = kmalloc(buf->dev_priv_size, buf->dev_private = kzalloc(buf->dev_priv_size,
GFP_KERNEL); GFP_KERNEL);
if (!buf->dev_private) { if (!buf->dev_private) {
/* Set count correctly so we free the proper amount. */ /* Set count correctly so we free the proper amount. */
...@@ -923,7 +918,6 @@ int drm_addbufs_pci(struct drm_device * dev, struct drm_buf_desc * request) ...@@ -923,7 +918,6 @@ int drm_addbufs_pci(struct drm_device * dev, struct drm_buf_desc * request)
atomic_dec(&dev->buf_alloc); atomic_dec(&dev->buf_alloc);
return -ENOMEM; return -ENOMEM;
} }
memset(buf->dev_private, 0, buf->dev_priv_size);
DRM_DEBUG("buffer %d @ %p\n", DRM_DEBUG("buffer %d @ %p\n",
entry->buf_count, buf->address); entry->buf_count, buf->address);
...@@ -1048,14 +1042,13 @@ static int drm_addbufs_sg(struct drm_device * dev, struct drm_buf_desc * request ...@@ -1048,14 +1042,13 @@ static int drm_addbufs_sg(struct drm_device * dev, struct drm_buf_desc * request
return -EINVAL; return -EINVAL;
} }
entry->buflist = kmalloc(count * sizeof(*entry->buflist), entry->buflist = kzalloc(count * sizeof(*entry->buflist),
GFP_KERNEL); GFP_KERNEL);
if (!entry->buflist) { if (!entry->buflist) {
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
atomic_dec(&dev->buf_alloc); atomic_dec(&dev->buf_alloc);
return -ENOMEM; return -ENOMEM;
} }
memset(entry->buflist, 0, count * sizeof(*entry->buflist));
entry->buf_size = size; entry->buf_size = size;
entry->page_order = page_order; entry->page_order = page_order;
...@@ -1080,7 +1073,7 @@ static int drm_addbufs_sg(struct drm_device * dev, struct drm_buf_desc * request ...@@ -1080,7 +1073,7 @@ static int drm_addbufs_sg(struct drm_device * dev, struct drm_buf_desc * request
buf->file_priv = NULL; buf->file_priv = NULL;
buf->dev_priv_size = dev->driver->dev_priv_size; buf->dev_priv_size = dev->driver->dev_priv_size;
buf->dev_private = kmalloc(buf->dev_priv_size, GFP_KERNEL); buf->dev_private = kzalloc(buf->dev_priv_size, GFP_KERNEL);
if (!buf->dev_private) { if (!buf->dev_private) {
/* Set count correctly so we free the proper amount. */ /* Set count correctly so we free the proper amount. */
entry->buf_count = count; entry->buf_count = count;
...@@ -1090,8 +1083,6 @@ static int drm_addbufs_sg(struct drm_device * dev, struct drm_buf_desc * request ...@@ -1090,8 +1083,6 @@ static int drm_addbufs_sg(struct drm_device * dev, struct drm_buf_desc * request
return -ENOMEM; return -ENOMEM;
} }
memset(buf->dev_private, 0, buf->dev_priv_size);
DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address); DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address);
offset += alignment; offset += alignment;
...@@ -1209,14 +1200,13 @@ static int drm_addbufs_fb(struct drm_device * dev, struct drm_buf_desc * request ...@@ -1209,14 +1200,13 @@ static int drm_addbufs_fb(struct drm_device * dev, struct drm_buf_desc * request
return -EINVAL; return -EINVAL;
} }
entry->buflist = kmalloc(count * sizeof(*entry->buflist), entry->buflist = kzalloc(count * sizeof(*entry->buflist),
GFP_KERNEL); GFP_KERNEL);
if (!entry->buflist) { if (!entry->buflist) {
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
atomic_dec(&dev->buf_alloc); atomic_dec(&dev->buf_alloc);
return -ENOMEM; return -ENOMEM;
} }
memset(entry->buflist, 0, count * sizeof(*entry->buflist));
entry->buf_size = size; entry->buf_size = size;
entry->page_order = page_order; entry->page_order = page_order;
...@@ -1240,7 +1230,7 @@ static int drm_addbufs_fb(struct drm_device * dev, struct drm_buf_desc * request ...@@ -1240,7 +1230,7 @@ static int drm_addbufs_fb(struct drm_device * dev, struct drm_buf_desc * request
buf->file_priv = NULL; buf->file_priv = NULL;
buf->dev_priv_size = dev->driver->dev_priv_size; buf->dev_priv_size = dev->driver->dev_priv_size;
buf->dev_private = kmalloc(buf->dev_priv_size, GFP_KERNEL); buf->dev_private = kzalloc(buf->dev_priv_size, GFP_KERNEL);
if (!buf->dev_private) { if (!buf->dev_private) {
/* Set count correctly so we free the proper amount. */ /* Set count correctly so we free the proper amount. */
entry->buf_count = count; entry->buf_count = count;
...@@ -1249,7 +1239,6 @@ static int drm_addbufs_fb(struct drm_device * dev, struct drm_buf_desc * request ...@@ -1249,7 +1239,6 @@ static int drm_addbufs_fb(struct drm_device * dev, struct drm_buf_desc * request
atomic_dec(&dev->buf_alloc); atomic_dec(&dev->buf_alloc);
return -ENOMEM; return -ENOMEM;
} }
memset(buf->dev_private, 0, buf->dev_priv_size);
DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address); DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment