Skip to contentSkip to conversation

drm/ttm/nouveau: don't call tt destroy callback on alloc failure.

PATCH In review Ben Hutchings 2 participants 2 messages Jan 24, 2022 Stable branch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/ttm/nouveau: don't call tt destroy callback on alloc failure.

From: Dave Airlie <[email protected]>

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).

[bwh: Backported to 4.14:
- Drop change in ttm_sg_tt_init()
- Adjust context]

---
 drivers/gpu/drm/nouveau/nouveau_sgdma.c | 9 +++------
 drivers/gpu/drm/ttm/ttm_tt.c            | 2 --
 2 files changed, 3 insertions(+), 8 deletions(-)
drivers/gpu/drm/nouveau/nouveau_sgdma.c +3 -6
index fde11ce466e4..495c4043467e 100644
@@ -106,12 +106,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;
 }
drivers/gpu/drm/ttm/ttm_tt.c +0 -2
index 8ebc8d3560c3..fc8bdcc1541b 100644
@@ -199,7 +199,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;
 	}
@@ -232,7 +231,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;
 	}
maintainer
#1 lore raw
Quoted 17 lines · Ben Hutchings

From: Dave Airlie <[email protected]>

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).

Quoted 8 lines

[bwh: Backported to 4.14:
- Drop change in ttm_sg_tt_init()
- Adjust context]

---
 drivers/gpu/drm/nouveau/nouveau_sgdma.c | 9 +++------
 drivers/gpu/drm/ttm/ttm_tt.c            | 2 --
 2 files changed, 3 insertions(+), 8 deletions(-)

Now queued up, thanks for the backport!

greg k-h