From fb366a915a43e2eb92cc455bbd665f66e4c0fc05 Mon Sep 17 00:00:00 2001 From: jsg Date: Wed, 20 Mar 2024 03:02:24 +0000 Subject: [PATCH] handle ttm_sg_tt_init() not being called before ttm_tt_fini() Check that dmamap and segs are non-NULL as not all drivers call ttm_sg_tt_init(). --- sys/dev/pci/drm/ttm/ttm_tt.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sys/dev/pci/drm/ttm/ttm_tt.c b/sys/dev/pci/drm/ttm/ttm_tt.c index 38625196072..21d1d9cfe70 100644 --- a/sys/dev/pci/drm/ttm/ttm_tt.c +++ b/sys/dev/pci/drm/ttm/ttm_tt.c @@ -151,6 +151,9 @@ static void ttm_tt_init_fields(struct ttm_tt *ttm, ttm->swap_storage = NULL; ttm->sg = bo->sg; ttm->caching = caching; + ttm->dmat = bo->bdev->dmat; + ttm->map = NULL; + ttm->segs = NULL; } int ttm_tt_init(struct ttm_tt *ttm, struct ttm_buffer_object *bo, @@ -184,9 +187,11 @@ void ttm_tt_fini(struct ttm_tt *ttm) ttm->dma_address = NULL; ttm->orders = NULL; - bus_dmamap_destroy(ttm->dmat, ttm->map); - km_free(ttm->segs, round_page(ttm->num_pages * - sizeof(bus_dma_segment_t)), &kv_any, &kp_zero); + if (ttm->map) + bus_dmamap_destroy(ttm->dmat, ttm->map); + if (ttm->segs) + km_free(ttm->segs, round_page(ttm->num_pages * + sizeof(bus_dma_segment_t)), &kv_any, &kp_zero); } EXPORT_SYMBOL(ttm_tt_fini); @@ -210,8 +215,6 @@ int ttm_sg_tt_init(struct ttm_tt *ttm, struct ttm_buffer_object *bo, ttm->segs = km_alloc(round_page(ttm->num_pages * sizeof(bus_dma_segment_t)), &kv_any, &kp_zero, &kd_waitok); - ttm->dmat = bo->bdev->dmat; - if (bo->bdev->pool.use_dma32 == false) flags |= BUS_DMA_64BIT; if (bus_dmamap_create(ttm->dmat, ttm->num_pages << PAGE_SHIFT, -- 2.20.1