summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorJonathan Gray <jsg@cvs.openbsd.org>2019-06-11 06:46:54 +0000
committerJonathan Gray <jsg@cvs.openbsd.org>2019-06-11 06:46:54 +0000
commit19c4106ecf4fd9bc37021ebdce910c3e64fecd42 (patch)
treec44bbf16239f6df9d2ec244a3a2d2112e7b3360a /sys
parent17e9b3bf244c9eaf2e162921bad659d7a10cbe13 (diff)
Use km_alloc() instead of mallocarray() when allocating ttm dma segments
to avoid running out of kmem space. Suggested by and ok kettenis@
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/pci/drm/ttm/ttm_tt.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/sys/dev/pci/drm/ttm/ttm_tt.c b/sys/dev/pci/drm/ttm/ttm_tt.c
index ece237259d8..5c7fbbbafc9 100644
--- a/sys/dev/pci/drm/ttm/ttm_tt.c
+++ b/sys/dev/pci/drm/ttm/ttm_tt.c
@@ -272,8 +272,8 @@ int ttm_dma_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_buffer_object *bo,
return -ENOMEM;
}
- ttm_dma->segs = mallocarray(ttm->num_pages,
- sizeof(bus_dma_segment_t), M_DRM, M_WAITOK | M_ZERO);
+ ttm_dma->segs = km_alloc(round_page(ttm->num_pages *
+ sizeof(bus_dma_segment_t)), &kv_any, &kp_zero, &kd_waitok);
ttm_dma->dmat = bo->bdev->dmat;
@@ -282,7 +282,8 @@ int ttm_dma_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_buffer_object *bo,
if (bus_dmamap_create(ttm_dma->dmat, ttm->num_pages << PAGE_SHIFT,
ttm->num_pages, ttm->num_pages << PAGE_SHIFT, 0, flags,
&ttm_dma->map)) {
- free(ttm_dma->segs, M_DRM, 0);
+ km_free(ttm_dma->segs, round_page(ttm->num_pages *
+ sizeof(bus_dma_segment_t)), &kv_any, &kp_zero);
ttm_tt_destroy(ttm);
pr_err("Failed allocating page table\n");
return -ENOMEM;
@@ -312,8 +313,8 @@ int ttm_sg_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_buffer_object *bo,
return -ENOMEM;
}
- ttm_dma->segs = mallocarray(ttm->num_pages,
- sizeof(bus_dma_segment_t), M_DRM, M_WAITOK | M_ZERO);
+ ttm_dma->segs = km_alloc(round_page(ttm->num_pages *
+ sizeof(bus_dma_segment_t)), &kv_any, &kp_zero, &kd_waitok);
ttm_dma->dmat = bo->bdev->dmat;
@@ -322,7 +323,8 @@ int ttm_sg_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_buffer_object *bo,
if (bus_dmamap_create(ttm_dma->dmat, ttm->num_pages << PAGE_SHIFT,
ttm->num_pages, ttm->num_pages << PAGE_SHIFT, 0, flags,
&ttm_dma->map)) {
- free(ttm_dma->segs, M_DRM, 0);
+ km_free(ttm_dma->segs, round_page(ttm->num_pages *
+ sizeof(bus_dma_segment_t)), &kv_any, &kp_zero);
ttm_tt_destroy(ttm);
pr_err("Failed allocating page table\n");
return -ENOMEM;
@@ -344,7 +346,8 @@ void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma)
ttm_dma->dma_address = NULL;
bus_dmamap_destroy(ttm_dma->dmat, ttm_dma->map);
- free(ttm_dma->segs, M_DRM, 0);
+ km_free(ttm_dma->segs, round_page(ttm->num_pages *
+ sizeof(bus_dma_segment_t)), &kv_any, &kp_zero);
}
EXPORT_SYMBOL(ttm_dma_tt_fini);