drm: sgdma: free allocated memory if TT init fails
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
@@ -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
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 innouveau_sgdma_create_ttm(), we should free the previously allocated memory before returning NULL.Signed-off-by Alexandre Courbot <[email protected]>--- drm/nouveau_sgdma.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drm/nouveau_sgdma.c +4
-2@@ -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
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
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-> kfreeUrrk.
..... 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