drm/ttm/nouveau: don't call tt destroy callback on alloc failure.
authorDave Airlie <airlied@redhat.com>
Tue, 28 Jul 2020 04:17:36 +0000 (14:17 +1000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 27 Jan 2022 07:47:42 +0000 (08:47 +0100)
commit 5de5b6ecf97a021f29403aa272cb4e03318ef586 upstream.

This is confusing, and from my reading of all the drivers only
nouveau got this right.

Just make the API act under driver control of it's own allocation
failing, and don't call destroy, if the page table fails to
create there is nothing to cleanup here.

(I'm willing to believe I've missed something here, so please
review deeply).

Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200728041736.20689-1-airlied@gmail.com
[bwh: Backported to 4.14:
 - Drop change in ttm_sg_tt_init()
 - Adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/gpu/drm/nouveau/nouveau_sgdma.c
drivers/gpu/drm/ttm/ttm_tt.c

index db35ab5883acdf20deef20f21f2b5430fe61da0c..d3bfd7912a99497843a2b3b4779722e1dd0c39db 100644 (file)
@@ -105,12 +105,9 @@ nouveau_sgdma_create_ttm(struct ttm_bo_device *bdev,
        else
                nvbe->ttm.ttm.func = &nv50_sgdma_backend;
 
-       if (ttm_dma_tt_init(&nvbe->ttm, bdev, size, page_flags, dummy_read_page))
-               /*
-                * A failing ttm_dma_tt_init() will call ttm_tt_destroy()
-                * and thus our nouveau_sgdma_destroy() hook, so we don't need
-                * to free nvbe here.
-                */
+       if (ttm_dma_tt_init(&nvbe->ttm, bdev, size, page_flags, dummy_read_page)) {
+               kfree(nvbe);
                return NULL;
+       }
        return &nvbe->ttm.ttm;
 }
index aee3c00f836e723fed991843c22eea5ca0b974d0..e4e24be52353302bf90572db3c06793856ce1584 100644 (file)
@@ -195,7 +195,6 @@ int ttm_tt_init(struct ttm_tt *ttm, struct ttm_bo_device *bdev,
 
        ttm_tt_alloc_page_directory(ttm);
        if (!ttm->pages) {
-               ttm_tt_destroy(ttm);
                pr_err("Failed allocating page table\n");
                return -ENOMEM;
        }
@@ -228,7 +227,6 @@ int ttm_dma_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_bo_device *bdev,
        INIT_LIST_HEAD(&ttm_dma->pages_list);
        ttm_dma_tt_alloc_page_directory(ttm_dma);
        if (!ttm->pages) {
-               ttm_tt_destroy(ttm);
                pr_err("Failed allocating page table\n");
                return -ENOMEM;
        }