and drm_calloc.
With the recent change to check overflow in drm_calloc, this means that
all allocations that require multiplication are now checked. Also use
drm_calloc() when zeroing is needed and drop the bzero/memset
afterwards. Finally, make drm_free() check for NULL, so we don't need
to do so every time.
ok miod@, deraadt@
#define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */
#define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */
-#define DRM_MEM_DMA 0
-#define DRM_MEM_SAREA 1
-#define DRM_MEM_DRIVER 2
-#define DRM_MEM_MAGIC 3
-#define DRM_MEM_IOCTLS 4
-#define DRM_MEM_MAPS 5
-#define DRM_MEM_BUFS 6
-#define DRM_MEM_SEGS 7
-#define DRM_MEM_PAGES 8
-#define DRM_MEM_FILES 9
-#define DRM_MEM_QUEUES 10
-#define DRM_MEM_CMDS 11
-#define DRM_MEM_MAPPINGS 12
-#define DRM_MEM_BUFLISTS 13
-#define DRM_MEM_AGPLISTS 14
-#define DRM_MEM_TOTALAGP 15
-#define DRM_MEM_BOUNDAGP 16
-#define DRM_MEM_CTXBITMAP 17
-#define DRM_MEM_STUB 18
-#define DRM_MEM_SGLISTS 19
-#define DRM_MEM_DRAWABLE 20
-#define DRM_MEM_MM 21
+#define DRM_MEM_DMA 0
+#define DRM_MEM_SAREA 1
+#define DRM_MEM_DRIVER 2
+#define DRM_MEM_MAGIC 3
+#define DRM_MEM_IOCTLS 4
+#define DRM_MEM_MAPS 5
+#define DRM_MEM_BUFS 6
+#define DRM_MEM_SEGS 7
+#define DRM_MEM_PAGES 8
+#define DRM_MEM_FILES 9
+#define DRM_MEM_QUEUES 10
+#define DRM_MEM_CMDS 11
+#define DRM_MEM_MAPPINGS 12
+#define DRM_MEM_BUFLISTS 13
+#define DRM_MEM_AGPLISTS 14
+#define DRM_MEM_TOTALAGP 15
+#define DRM_MEM_BOUNDAGP 16
+#define DRM_MEM_CTXBITMAP 17
+#define DRM_MEM_CTXLIST 18
+#define DRM_MEM_STUB 19
+#define DRM_MEM_SGLISTS 20
+#define DRM_MEM_DRAWABLE 21
+#define DRM_MEM_MM 22
#define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
bus_dmamap_t dmamap;
bus_dma_segment_t seg;
void *addr;
- bus_addr_t dmaaddr;
size_t size;
} drm_dma_handle_t;
if (!dev->agp || !dev->agp->acquired)
return EINVAL;
- entry = malloc(sizeof(*entry), M_DRM, M_NOWAIT | M_ZERO);
+ entry = drm_alloc(sizeof(*entry), DRM_MEM_AGPLISTS);
if (entry == NULL)
return ENOMEM;
handle = drm_agp_allocate_memory(pages, type);
DRM_LOCK();
if (handle == NULL) {
- free(entry, M_DRM);
+ drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
return ENOMEM;
}
drm_agp_free_memory(entry->handle);
DRM_LOCK();
- free(entry, M_DRM);
+ drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
return 0;
DRM_DEBUG("agp_available = %d\n", agp_available);
if (agp_available) {
- head = malloc(sizeof(*head), M_DRM, M_NOWAIT | M_ZERO);
+ head = drm_calloc(1, sizeof(*head), DRM_MEM_AGPLISTS);
if (head == NULL)
return NULL;
head->agpdev = agpdev;
DRM_SPINLOCK_ASSERT(&dev->dev_lock);
- if ((entry = malloc(sizeof(*entry), M_DRM, M_ZERO | M_NOWAIT)) == NULL)
+ if ((entry = drm_alloc(sizeof(*entry), DRM_MEM_MAGIC)) == NULL)
return (ENOMEM);
entry->magic = magic;
entry->priv = priv;
if ((pt = SPLAY_FIND(drm_magic_tree, &dev->magiclist, &key)) == NULL)
return (EINVAL);
SPLAY_REMOVE(drm_magic_tree, &dev->magiclist, pt);
- free(pt, M_DRM);
+ drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC);
return (0);
}
/* Allocate a new map structure, fill it in, and do any type-specific
* initialization necessary.
*/
- map = malloc(sizeof(*map), M_DRM, M_ZERO | M_NOWAIT);
+ map = drm_calloc(1, sizeof(*map), DRM_MEM_MAPS);
if ( !map ) {
DRM_LOCK();
return ENOMEM;
PAGE_SIZE, 0);
if (map->mm == NULL) {
DRM_ERROR("can't find free offset\n");
- free(map, M_DRM);
+ drm_free(map, sizeof(*map), DRM_MEM_MAPS);
return ENOMEM;
}
map->mm = drm_memrange_get_block(map->mm, map->size,
PAGE_SIZE);
if (map->mm == NULL) {
DRM_ERROR("can't get block\n");
- free(map, M_DRM);
+ drm_free(map, sizeof(*map), DRM_MEM_MAPS);
return ENOMEM;
}
}
}
if (!TAILQ_EMPTY(&dev->agp->memory) && !valid) {
- free(map, M_DRM);
+ drm_free(map, sizeof(*map), DRM_MEM_MAPS);
DRM_LOCK();
DRM_ERROR("invalid agp map requested\n");
return EACCES;
break;
case _DRM_SCATTER_GATHER:
if (!dev->sg) {
- free(map, M_DRM);
+ drm_free(map, sizeof(*map), DRM_MEM_MAPS);
DRM_LOCK();
return EINVAL;
}
align = PAGE_SIZE;
map->dmah = drm_pci_alloc(dev, map->size, align, 0xfffffffful);
if (map->dmah == NULL) {
- free(map, M_DRM);
+ drm_free(map, sizeof(*map), DRM_MEM_MAPS);
DRM_LOCK();
return ENOMEM;
}
if (dev->lock.hw_lock != NULL) {
DRM_UNLOCK();
drm_pci_free(dev, map->dmah);
- free(map, M_DRM);
+ drm_free(map, sizeof(*map), DRM_MEM_MAPS);
DRM_LOCK();
return EBUSY;
}
break;
default:
DRM_ERROR("Bad map type %d\n", map->type);
- free(map, M_DRM);
+ drm_free(map, sizeof(*map), DRM_MEM_MAPS);
DRM_LOCK();
return EINVAL;
}
drm_memrange_put_block(map->mm);
- free(map, M_DRM);
+ drm_free(map, sizeof(*map), DRM_MEM_MAPS);
}
/* Remove a map private from list and deallocate resources if the mapping
for (i = 0; i < entry->seg_count; i++) {
drm_pci_free(dev, entry->seglist[i]);
}
- free(entry->seglist, M_DRM);
+ drm_free(entry->seglist, entry->seg_count *
+ sizeof(*entry->seglist), DRM_MEM_BUFS);
entry->seg_count = 0;
}
if (entry->buf_count) {
for (i = 0; i < entry->buf_count; i++) {
- free(entry->buflist[i].dev_private, M_DRM);
+ drm_free(entry->buflist[i].dev_private,
+ entry->buflist[i].dev_priv_size, DRM_MEM_BUFS);
}
- free(entry->buflist, M_DRM);
+ drm_free(entry->buflist, entry->buf_count *
+ sizeof(*entry->buflist), DRM_MEM_BUFS);
entry->buf_count = 0;
}
entry = &dma->bufs[order];
- entry->buflist = malloc(count * sizeof(*entry->buflist), M_DRM,
- M_NOWAIT | M_ZERO);
+ entry->buflist = drm_calloc(count, sizeof(*entry->buflist),
+ DRM_MEM_BUFS);
if ( !entry->buflist ) {
return ENOMEM;
}
buf->file_priv = NULL;
buf->dev_priv_size = dev->driver.buf_priv_size;
- buf->dev_private = malloc(buf->dev_priv_size, M_DRM,
- M_NOWAIT | M_ZERO);
+ buf->dev_private = drm_calloc(1, buf->dev_priv_size,
+ DRM_MEM_BUFS);
if (buf->dev_private == NULL) {
/* Set count correctly so we free the proper amount. */
entry->buf_count = count;
entry = &dma->bufs[order];
- entry->buflist = malloc(count * sizeof(*entry->buflist), M_DRM,
- M_NOWAIT | M_ZERO);
- entry->seglist = malloc(count * sizeof(*entry->seglist), M_DRM,
- M_NOWAIT | M_ZERO);
+ entry->buflist = drm_calloc(count, sizeof(*entry->buflist),
+ DRM_MEM_BUFS);
+ entry->seglist = drm_calloc(count, sizeof(*entry->seglist),
+ DRM_MEM_BUFS);
/* Keep the original pagelist until we know all the allocations
* have succeeded
*/
- temp_pagelist = malloc((dma->page_count + (count << page_order)) *
- sizeof(*dma->pagelist), M_DRM, M_NOWAIT);
+ temp_pagelist = drm_calloc((dma->page_count + (count << page_order)),
+ sizeof(*dma->pagelist), DRM_MEM_BUFS);
if (entry->buflist == NULL || entry->seglist == NULL ||
temp_pagelist == NULL) {
- if (temp_pagelist)
- free(temp_pagelist, M_DRM);
- if (entry->seglist)
- free(entry->seglist, M_DRM);
- if (entry->buflist)
- free(entry->buflist, M_DRM);
+ drm_free(temp_pagelist, (dma->page_count + (count <<
+ page_order)) * sizeof(*dma->pagelist), DRM_MEM_BUFS);
+ drm_free(entry->seglist, count * sizeof(*entry->seglist),
+ DRM_MEM_BUFS);
+ drm_free(entry->buflist, count * sizeof(*entry->buflist),
+ DRM_MEM_BUFS);
return ENOMEM;
}
entry->buf_count = count;
entry->seg_count = count;
drm_cleanup_buf_error(dev, entry);
- free(temp_pagelist, M_DRM);
+ drm_free(temp_pagelist, (dma->page_count +
+ (count << page_order)) * sizeof(*dma->pagelist),
+ DRM_MEM_BUFS);
return ENOMEM;
}
buf->file_priv = NULL;
buf->dev_priv_size = dev->driver.buf_priv_size;
- buf->dev_private = malloc(buf->dev_priv_size, M_DRM,
- M_NOWAIT | M_ZERO);
+ buf->dev_private = drm_calloc(1, buf->dev_priv_size,
+ DRM_MEM_BUFS);
if (buf->dev_private == NULL) {
/* Set count correctly so we free the proper amount. */
entry->buf_count = count;
entry->seg_count = count;
drm_cleanup_buf_error(dev, entry);
- free(temp_pagelist, M_DRM);
+ drm_free(temp_pagelist, (dma->page_count +
+ (count << page_order)) *
+ sizeof(*dma->pagelist),
+ DRM_MEM_BUFS);
return ENOMEM;
}
if (temp_buflist == NULL) {
/* Free the entry because it isn't valid */
drm_cleanup_buf_error(dev, entry);
- free(temp_pagelist, M_DRM);
+ drm_free(temp_pagelist, (dma->page_count +
+ (count << page_order)) * sizeof(*dma->pagelist),
+ DRM_MEM_BUFS);
return ENOMEM;
}
dma->buflist = temp_buflist;
/* No allocations failed, so now we can replace the orginal pagelist
* with the new one.
*/
- free(dma->pagelist, M_DRM);
+ drm_free(dma->pagelist, dma->page_count * sizeof(*dma->pagelist),
+ DRM_MEM_BUFS);
dma->pagelist = temp_pagelist;
dma->buf_count += entry->buf_count;
entry = &dma->bufs[order];
- entry->buflist = malloc(count * sizeof(*entry->buflist), M_DRM,
- M_NOWAIT | M_ZERO);
+ entry->buflist = drm_calloc(count, sizeof(*entry->buflist),
+ DRM_MEM_BUFS);
if (entry->buflist == NULL)
return ENOMEM;
buf->file_priv = NULL;
buf->dev_priv_size = dev->driver.buf_priv_size;
- buf->dev_private = malloc(buf->dev_priv_size, M_DRM,
- M_NOWAIT | M_ZERO);
+ buf->dev_private = drm_calloc(1, buf->dev_priv_size,
+ DRM_MEM_BUFS);
if (buf->dev_private == NULL) {
/* Set count correctly so we free the proper amount. */
entry->buf_count = count;
dev->context_sareas[bit] = NULL;
} else {
/* max_context == 1 at this point */
- dev->context_sareas = malloc(dev->max_context *
- sizeof(*dev->context_sareas), M_DRM, M_NOWAIT);
+ dev->context_sareas = drm_calloc(dev->max_context,
+ sizeof(*dev->context_sareas), DRM_MEM_CTXLIST);
if (dev->context_sareas == NULL) {
clear_bit(bit, dev->ctx_bitmap);
DRM_UNLOCK();
int temp;
DRM_LOCK();
- dev->ctx_bitmap = malloc(PAGE_SIZE, M_DRM, M_NOWAIT | M_ZERO);
+ dev->ctx_bitmap = drm_calloc(1, PAGE_SIZE, DRM_MEM_CTXBITMAP);
if ( dev->ctx_bitmap == NULL ) {
DRM_UNLOCK();
return ENOMEM;
drm_ctxbitmap_cleanup(struct drm_device *dev)
{
DRM_LOCK();
- if (dev->context_sareas != NULL)
- free(dev->context_sareas, M_DRM);
- free(dev->ctx_bitmap, M_DRM);
+ drm_free(dev->context_sareas,
+ sizeof(dev->context_sareas) * dev->max_context, DRM_MEM_CTXLIST);
+ drm_free(dev->ctx_bitmap, PAGE_SIZE, DRM_MEM_CTXBITMAP);
DRM_UNLOCK();
}
drm_dma_setup(struct drm_device *dev)
{
- dev->dma = malloc(sizeof(*dev->dma), M_DRM, M_NOWAIT | M_ZERO);
+ dev->dma = drm_calloc(1, sizeof(*dev->dma), DRM_MEM_DRIVER);
if (dev->dma == NULL)
return ENOMEM;
if (dma->pagelist)
free(dma->pagelist, M_DRM);
if (dev->dma)
- free(dev->dma, M_DRM);
+ drm_free(dev->dma, sizeof(*dev->dma), DRM_MEM_DMA);
dev->dma = NULL;
DRM_SPINUNINIT(&dev->dma_lock);
}
return 0;
}
if (info->rects == NULL) {
- info->rects = drm_alloc(sizeof(*info->rects) *
+ info->rects = drm_calloc(sizeof(*info->rects),
update->num, DRM_MEM_DRAWABLE);
if (info->rects == NULL) {
DRM_SPINUNLOCK(&dev->drw_lock);
void
drm_drawable_free(struct drm_device *dev, struct bsd_drm_drawable_info *draw)
{
- if (draw) {
- RB_REMOVE(drawable_tree, &dev->drw_head, draw);
- if (draw->info.rects)
- drm_free(draw->info.rects,
- sizeof(*draw->info.rects) * draw->info.num_rects,
- DRM_MEM_DRAWABLE);
- drm_free(draw, sizeof(*draw),
- DRM_MEM_DRAWABLE);
- }
+ if (draw == NULL)
+ return;
+ RB_REMOVE(drawable_tree, &dev->drw_head, draw);
+ drm_free(draw->info.rects,
+ sizeof(*draw->info.rects) * draw->info.num_rects, DRM_MEM_DRAWABLE);
+ drm_free(draw, sizeof(*draw), DRM_MEM_DRAWABLE);
}
void
drm_irq_uninstall(dev);
if ( dev->unique ) {
- free(dev->unique, M_DRM);
+ drm_free(dev->unique, dev->unique_len + 1, DRM_MEM_DRIVER);
dev->unique = NULL;
dev->unique_len = 0;
}
/* Clear pid list */
while ((pt = SPLAY_ROOT(&dev->magiclist)) != NULL) {
SPLAY_REMOVE(drm_magic_tree, &dev->magiclist, pt);
- free(pt, M_DRM);
+ drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC);
}
/* Clear AGP information */
drm_agp_unbind_memory(entry->handle);
drm_agp_free_memory(entry->handle);
TAILQ_REMOVE(&dev->agp->memory, entry, link);
- free(entry, M_DRM);
+ drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
}
if (dev->agp->acquired)
DRM_UNLOCK();
if ( dev->agp ) {
- free(dev->agp, M_DRM);
+ drm_free(dev->agp, sizeof(*dev->agp), DRM_MEM_AGPLISTS);
dev->agp = NULL;
}
if (dev->driver.postclose != NULL)
dev->driver.postclose(dev, file_priv);
TAILQ_REMOVE(&dev->files, file_priv, link);
- free(file_priv, M_DRM);
+ drm_free(file_priv, sizeof(*file_priv), DRM_MEM_FILES);
/* ========================================================
* End inline drm_release
if (priv) {
priv->refs++;
} else {
- priv = malloc(sizeof(*priv), M_DRM, M_NOWAIT | M_ZERO);
+ priv = drm_calloc(1, sizeof(*priv), DRM_MEM_FILES);
if (priv == NULL) {
DRM_UNLOCK();
return ENOMEM;
priv->refs = 1;
priv->minor = m;
- priv->ioctl_count = 0;
/* for compatibility root is always authenticated */
priv->authenticated = DRM_SUSER(p);
/* shared code returns -errno */
retcode = -dev->driver.open(dev, priv);
if (retcode != 0) {
- free(priv, M_DRM);
+ drm_free(priv, sizeof(*priv), DRM_MEM_FILES);
DRM_UNLOCK();
return retcode;
}
/* first opener automatically becomes master if root */
if (TAILQ_EMPTY(&dev->files) && !DRM_SUSER(p)) {
- free(priv, M_DRM);
+ drm_free(priv, sizeof(*priv), DRM_MEM_FILES);
DRM_UNLOCK();
return (EPERM);
}
if (!u->unique_len || u->unique_len > 1024)
return EINVAL;
- busid = malloc(u->unique_len + 1, M_DRM, M_WAITOK);
+ busid = drm_alloc(u->unique_len + 1, DRM_MEM_DRIVER);
if (busid == NULL)
return ENOMEM;
if (DRM_COPY_FROM_USER(busid, u->unique, u->unique_len)) {
- free(busid, M_DRM);
+ drm_free(busid, u->unique_len + 1, DRM_MEM_DRIVER);
return EFAULT;
}
busid[u->unique_len] = '\0';
#endif /* Net and Openbsd don't have sscanf in the kernel this is deprecated anyway. */
if (ret != 3) {
- free(busid, M_DRM);
+ drm_free(busid, u->unique_len + 1, DRM_MEM_DRIVER);
return EINVAL;
}
domain = bus >> 8;
(bus != dev->pci_bus) ||
(slot != dev->pci_slot) ||
(func != dev->pci_func)) {
- free(busid, M_DRM);
+ drm_free(busid, u->unique_len + 1, DRM_MEM_DRIVER);
return EINVAL;
}
}
dev->unique_len = 20;
- dev->unique = malloc(dev->unique_len + 1, M_DRM, M_NOWAIT);
+ dev->unique = drm_alloc(dev->unique_len + 1, DRM_MEM_DRIVER);
if (dev->unique == NULL) {
DRM_UNLOCK();
return ENOMEM;
if (flags & _DRM_VBLANK_SIGNAL) {
#if 0 /* disabled */
- if (dev->vblank_suspend[crtc])
- return (EBUSY);
-
- drm_vbl_sig_t *vbl_sig = malloc(sizeof(drm_vbl_sig_t), M_DRM,
- M_NOWAIT | M_ZERO);
+ drm_vbl_sig_t *vbl_sig = drm_calloc(1, sizeof(drm_vbl_sig_t),
+ DRM_MEM_DRIVER);
if (vbl_sig == NULL)
return ENOMEM;
psignal(p, vbl_sig->signo);
TAILQ_REMOVE(&dev->vbl_sig_list, vbl_sig, link);
- DRM_FREE(vbl_sig,sizeof(*vbl_sig));
+ drm_free(vbl_sig, sizeof(*vbl_sig), DRM_MEM_DRIVER);
}
vbl_sig = next;
}
void
drm_free(void *pt, size_t size, int area)
{
- free(pt, M_DRM);
+ if (pt != NULL)
+ free(pt, M_DRM);
}
void *
return NULL;
}
- dmah = malloc(sizeof(drm_dma_handle_t), M_DRM, M_ZERO | M_NOWAIT);
+ dmah = drm_alloc(sizeof(*dmah), DRM_MEM_DMA);
if (dmah == NULL)
return NULL;
destroy:
bus_dmamap_destroy(dev->pa.pa_dmat, dmah->dmamap);
dmahfree:
- free(dmah, M_DRM);
+ drm_free(dmah, sizeof(*dmah), DRM_MEM_DMA);
return (NULL);
bus_dmamem_free(dev->pa.pa_dmat, &dmah->seg, 1);
bus_dmamap_destroy(dev->pa.pa_dmat, dmah->dmamap);
- free(dmah, M_DRM);
+ drm_free(dmah, sizeof(*dmah), DRM_MEM_DMA);
}
/*@}*/
void
drm_sg_cleanup(drm_sg_mem_t *entry)
{
- if (entry) {
- if (entry->mem)
+ if (entry != NULL) {
+ if (entry->mem != NULL)
drm_sg_dmamem_free(entry->mem);
- if (entry->busaddr)
- free(entry->busaddr, M_DRM);
- free(entry, M_DRM);
+ drm_free(entry->busaddr,
+ sizeof(*entry->busaddr) * entry->pages, DRM_MEM_SGLISTS);
+ drm_free(entry, sizeof(entry), DRM_MEM_SGLISTS);
}
}
if ( dev->sg )
return EINVAL;
- entry = malloc(sizeof(*entry), M_DRM, M_WAITOK | M_ZERO);
- if ( !entry )
- return ENOMEM;
+ entry = drm_calloc(1, sizeof(*entry), DRM_MEM_SGLISTS);
+ if ( !entry )
+ return ENOMEM;
pages = round_page(request->size) / PAGE_SIZE;
DRM_DEBUG( "sg size=%ld pages=%ld\n", request->size, pages );
entry->pages = pages;
- entry->busaddr = malloc(pages * sizeof(*entry->busaddr), M_DRM,
- M_WAITOK | M_ZERO);
+ entry->busaddr = drm_calloc(pages, sizeof(*entry->busaddr),
+ DRM_MEM_SGLISTS);
if ( !entry->busaddr ) {
drm_sg_cleanup(entry);
return ENOMEM;
bus_size_t size = pages << PAGE_SHIFT;
int ret = 0;
- dsd = malloc(sizeof(*dsd), M_DRM, M_NOWAIT | M_ZERO);
+ dsd = drm_calloc(1, sizeof(*dsd), DRM_MEM_SGLISTS);
if (dsd == NULL)
return (NULL);
- dsd->sg_segs = malloc(sizeof(*dsd->sg_segs) * pages, M_DRM,
- M_NOWAIT | M_ZERO);
+ dsd->sg_segs = drm_calloc(sizeof(*dsd->sg_segs), pages,
+ DRM_MEM_SGLISTS);
if (dsd->sg_segs == NULL)
goto dsdfree;
destroy:
bus_dmamap_destroy(dev->pa.pa_dmat, dsd->sg_map);
segsfree:
- free(dsd->sg_segs, M_DRM);
+ drm_free(dsd->sg_segs, sizeof(*dsd->sg_segs) * pages, DRM_MEM_SGLISTS);
dsdfree:
- free(dsd, M_DRM);
+ drm_free(dsd, sizeof(*dsd), DRM_MEM_SGLISTS);
return (NULL);
}
bus_dmamem_unmap(mem->sg_tag, mem->sg_kva, mem->sg_size);
bus_dmamem_free(mem->sg_tag, mem->sg_segs, mem->sg_nsegs);
bus_dmamap_destroy(mem->sg_tag, mem->sg_map);
- free(mem->sg_segs, M_DRM);
- free(mem, M_DRM);
+ drm_free(mem->sg_segs, sizeof(*mem->sg_segs) *
+ (mem->sg_size >> PAGE_SHIFT), DRM_MEM_SGLISTS);
+ drm_free(mem, sizeof(*mem), DRM_MEM_SGLISTS);
}
dev->types[8] = _DRM_STAT_SECONDARY;
dev->types[9] = _DRM_STAT_DMA;
- dev_priv = drm_alloc(sizeof(drm_i915_private_t), DRM_MEM_DRIVER);
+ dev_priv = drm_calloc(1, sizeof(drm_i915_private_t), DRM_MEM_DRIVER);
if (dev_priv == NULL)
return -ENOMEM;
- memset(dev_priv, 0, sizeof(drm_i915_private_t));
-
dev->dev_private = (void *)dev_priv;
/* Add register map (needed for suspend/resume) */
DRM_DEBUG("\n");
- dev_priv = drm_alloc(sizeof(drm_mach64_private_t), DRM_MEM_DRIVER);
+ dev_priv = drm_calloc(1, sizeof(drm_mach64_private_t), DRM_MEM_DRIVER);
if (dev_priv == NULL)
return -ENOMEM;
- memset(dev_priv, 0, sizeof(drm_mach64_private_t));
-
dev_priv->is_pci = init->is_pci;
dev_priv->fb_bpp = init->fb_bpp;
for (i = 0; i < dma->buf_count; i++) {
if ((entry =
(drm_mach64_freelist_t *)
- drm_alloc(sizeof(drm_mach64_freelist_t),
+ drm_calloc(1, sizeof(drm_mach64_freelist_t),
DRM_MEM_BUFLISTS)) == NULL)
return -ENOMEM;
- memset(entry, 0, sizeof(drm_mach64_freelist_t));
entry->buf = dma->buflist[i];
ptr = &entry->list;
list_add_tail(ptr, &dev_priv->free_list);
int i;
DRM_DEBUG("count=%d\n", dma->buf_count);
- dev_priv->head = drm_alloc(sizeof(drm_mga_freelist_t), DRM_MEM_DRIVER);
+ dev_priv->head = drm_calloc(1, sizeof(drm_mga_freelist_t), DRM_MEM_DRIVER);
if (dev_priv->head == NULL)
return -ENOMEM;
- memset(dev_priv->head, 0, sizeof(drm_mga_freelist_t));
SET_AGE(&dev_priv->head->age, MGA_BUFFER_USED, 0);
for (i = 0; i < dma->buf_count; i++) {
buf = dma->buflist[i];
buf_priv = buf->dev_private;
- entry = drm_alloc(sizeof(drm_mga_freelist_t), DRM_MEM_DRIVER);
+ entry = drm_calloc(1, sizeof(drm_mga_freelist_t),
+ DRM_MEM_DRIVER);
if (entry == NULL)
return -ENOMEM;
- memset(entry, 0, sizeof(drm_mga_freelist_t));
-
entry->next = dev_priv->head->next;
entry->prev = dev_priv->head;
SET_AGE(&entry->age, MGA_BUFFER_FREE, 0);
{
drm_mga_private_t *dev_priv;
- dev_priv = drm_alloc(sizeof(drm_mga_private_t), DRM_MEM_DRIVER);
+ dev_priv = drm_calloc(1, sizeof(drm_mga_private_t), DRM_MEM_DRIVER);
if (!dev_priv)
return -ENOMEM;
dev->dev_private = (void *)dev_priv;
- memset(dev_priv, 0, sizeof(drm_mga_private_t));
dev_priv->usec_timeout = MGA_DEFAULT_USEC_TIMEOUT;
dev_priv->chipset = flags;
DRM_DEBUG("\n");
- dev_priv = drm_alloc(sizeof(drm_r128_private_t), DRM_MEM_DRIVER);
+ dev_priv = drm_calloc(1, sizeof(drm_r128_private_t), DRM_MEM_DRIVER);
if (dev_priv == NULL)
return -ENOMEM;
- memset(dev_priv, 0, sizeof(drm_r128_private_t));
-
dev_priv->is_pci = init->is_pci;
if (dev_priv->is_pci && !dev->sg) {
drm_r128_freelist_t *entry;
int i;
- dev_priv->head = drm_alloc(sizeof(drm_r128_freelist_t), DRM_MEM_DRIVER);
+ dev_priv->head = drm_calloc(1, sizeof(drm_r128_freelist_t),
+ DRM_MEM_DRIVER);
if (dev_priv->head == NULL)
return -ENOMEM;
- memset(dev_priv->head, 0, sizeof(drm_r128_freelist_t));
dev_priv->head->age = R128_BUFFER_USED;
for (i = 0; i < dma->buf_count; i++) {
drm_radeon_private_t *dev_priv;
int ret = 0;
- dev_priv = drm_alloc(sizeof(drm_radeon_private_t), DRM_MEM_DRIVER);
+ dev_priv = drm_calloc(1, sizeof(drm_radeon_private_t), DRM_MEM_DRIVER);
if (dev_priv == NULL)
return -ENOMEM;
- memset(dev_priv, 0, sizeof(drm_radeon_private_t));
dev->dev_private = (void *)dev_priv;
dev_priv->flags = flags;
if (!blocks)
return -ENOMEM;
- *heap = drm_alloc(sizeof(**heap), DRM_MEM_BUFS);
+ *heap = drm_calloc(1, sizeof(**heap), DRM_MEM_BUFS);
if (!*heap) {
drm_free(blocks, sizeof(*blocks), DRM_MEM_BUFS);
return -ENOMEM;
blocks->file_priv = NULL;
blocks->next = blocks->prev = *heap;
- memset(*heap, 0, sizeof(**heap));
(*heap)->file_priv = (struct drm_file *) - 1;
(*heap)->next = (*heap)->prev = blocks;
return 0;
dev_priv->nr_dma_pages = dev_priv->cmd_dma->size /
(SAVAGE_DMA_PAGE_SIZE*4);
- dev_priv->dma_pages = drm_alloc(sizeof(drm_savage_dma_page_t) *
- dev_priv->nr_dma_pages, DRM_MEM_DRIVER);
+ dev_priv->dma_pages = drm_calloc(sizeof(drm_savage_dma_page_t),
+ dev_priv->nr_dma_pages, DRM_MEM_DRIVER);
if (dev_priv->dma_pages == NULL)
return -ENOMEM;
{
drm_savage_private_t *dev_priv;
- dev_priv = drm_alloc(sizeof(drm_savage_private_t), DRM_MEM_DRIVER);
+ dev_priv = drm_calloc(1, sizeof(drm_savage_private_t), DRM_MEM_DRIVER);
if (dev_priv == NULL)
return -ENOMEM;
- memset(dev_priv, 0, sizeof(drm_savage_private_t));
dev->dev_private = (void *)dev_priv;
dev_priv->chipset = (enum savage_family)chipset;
dev_priv->fake_dma.size = SAVAGE_FAKE_DMA_SIZE;
dev_priv->fake_dma.type = _DRM_SHM;
dev_priv->fake_dma.handle = drm_alloc(SAVAGE_FAKE_DMA_SIZE,
- DRM_MEM_DRIVER);
+ DRM_MEM_DRIVER);
if (!dev_priv->fake_dma.handle) {
DRM_ERROR("could not allocate faked DMA buffer!\n");
savage_do_cleanup_bci(dev);
* for locking on FreeBSD.
*/
if (cmdbuf->size) {
- kcmd_addr = drm_alloc(cmdbuf->size * 8, DRM_MEM_DRIVER);
+ kcmd_addr = drm_calloc(cmdbuf->size, 8, DRM_MEM_DRIVER);
if (kcmd_addr == NULL)
return -ENOMEM;
cmdbuf->vb_addr = kvb_addr;
}
if (cmdbuf->nbox) {
- kbox_addr = drm_alloc(cmdbuf->nbox *
- sizeof(struct drm_clip_rect),
- DRM_MEM_DRIVER);
+ kbox_addr = drm_calloc(cmdbuf->nbox,
+ sizeof(struct drm_clip_rect), DRM_MEM_DRIVER);
if (kbox_addr == NULL) {
ret = -ENOMEM;
goto done;