drm/nouveau: properly handle allocation failure in nouveau_sgdma_populate
authorMarcin Slusarz <marcin.slusarz@gmail.com>
Mon, 22 Aug 2011 21:14:05 +0000 (23:14 +0200)
committerBen Skeggs <bskeggs@redhat.com>
Fri, 9 Sep 2011 07:24:06 +0000 (17:24 +1000)
Not cleaning after alloc failure would result in crash on destroy,
because nouveau_sgdma_clear assumes "ttm_alloced" to be not null when
"pages" is not null.

Signed-off-by: Marcin Slusarz <marcin.slusarz@gmail.com>
Cc: stable@kernel.org
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
drivers/gpu/drm/nouveau/nouveau_sgdma.c

index c444cadbf849110e4d3b418397f26e9524670ca0..88062de26b00dd4bc92714c0b7ff81dc0b97bcf2 100644 (file)
@@ -37,8 +37,11 @@ nouveau_sgdma_populate(struct ttm_backend *be, unsigned long num_pages,
                return -ENOMEM;
 
        nvbe->ttm_alloced = kmalloc(sizeof(bool) * num_pages, GFP_KERNEL);
-       if (!nvbe->ttm_alloced)
+       if (!nvbe->ttm_alloced) {
+               kfree(nvbe->pages);
+               nvbe->pages = NULL;
                return -ENOMEM;
+       }
 
        nvbe->nr_pages = 0;
        while (num_pages--) {