Skip to contentSkip to conversation

drm: sgdma: free allocated memory if TT init fails

PATCH In review Alexandre Courbot 3 participants 4 messages Dec 10, 2014 3 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm: sgdma: free allocated memory if TT init fails

When ttm_dma_tt_init() fails in nouveau_sgdma_create_ttm(), we should free the previously allocated memory before returning NULL.

---
 drm/nouveau_sgdma.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drm/nouveau_sgdma.c +4 -1
index 01707e7deaf5..e4fc494d688d 100644
@@ -107,7 +107,10 @@ 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))
+	if (ttm_dma_tt_init(&nvbe->ttm, bdev, size, page_flags, dummy_read_page)) {
+		kfree(nvbe);
 		return NULL;
+	}
+
 	return &nvbe->ttm.ttm;
 }
Signature · 6 lines
2.1.3

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
#2 lore raw
In reply to a message not in the archive

We get this patch every few months... How about one that instead adds a comment which explains why this kfree isn't needed :) [I'm leaving the reason to the reader, which will force you to glance at the ttm code.]

Quoted 27 lines · Alexandre Courbot

When ttm_dma_tt_init() fails in nouveau_sgdma_create_ttm(), we should free the previously allocated memory before returning NULL.

---
 drm/nouveau_sgdma.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drm/nouveau_sgdma.c +4 -2
index 01707e7deaf5..e4fc494d688d 100644
@@ -107,7 +107,10 @@ 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))
+       if (ttm_dma_tt_init(&nvbe->ttm, bdev, size, page_flags, dummy_read_page)) {
+               kfree(nvbe);
                return NULL;
+       }
+
        return &nvbe->ttm.ttm;
 }
--

2.1.3

Quoted 4 lines

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

#4 lore raw
In reply to a message not in the archive
Quoted 4 lines · Ilia Mirkin

We get this patch every few months... How about one that instead adds a comment which explains why this kfree isn't needed :) [I'm leaving the reason to the reader, which will force you to glance at the ttm code.]

ttm_dma_tt_init -> ttm_tt_destroy -> nouveau_sgdma_destroy -> kfree

Urrk.

I'm definitely not a fan of things happening this way, but let it be.

Indeed a comment would be nice to have here, let me prep a patch for this instead...
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

#6 lore raw
In reply to a message not in the archive
Quoted 6 lines · Alexandre Courbot
Quoted 5 lines · Ilia Mirkin

We get this patch every few months... How about one that instead adds a comment which explains why this kfree isn't needed :) [I'm leaving the reason to the reader, which will force you to glance at the ttm code.]

I'd quite like it if people looked at a bit more context for sending such patches......

Quoted 5 lines

ttm_dma_tt_init -> ttm_tt_destroy -> nouveau_sgdma_destroy -> kfree

Urrk.

..... That said.. I made the same mistake myself a few years back ;)

Quoted 5 lines

I'm definitely not a fan of things happening this way, but let it be.

Indeed a comment would be nice to have here, let me prep a patch for this instead...

I've picked up all three patches.

Thanks,
Ben.

Quoted 5 lines

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau