]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
staging: gasket: page table: fixup error path allocating coherent mem
authorNick Ewalt <nicholasewalt@google.com>
Mon, 15 Oct 2018 04:59:22 +0000 (21:59 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 15 Oct 2018 14:30:37 +0000 (16:30 +0200)
Correctly clean up data structure state in gasket_alloc_coherent_memory
error path, to ensure no double free on the stale pointer value.

Signed-off-by: Nick Ewalt <nicholasewalt@google.com>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/gasket/gasket_page_table.c

index 9c2f8671216b505d77cc7b9247e434db3e208239..a88f2ae0cee8bc38de2173f5247e0ea27f6033ef 100644 (file)
@@ -1332,9 +1332,13 @@ int gasket_alloc_coherent_memory(struct gasket_dev *gasket_dev, u64 size,
        return 0;
 
 nomem:
-       if (mem)
+       if (mem) {
                dma_free_coherent(gasket_get_device(gasket_dev),
                                  num_pages * PAGE_SIZE, mem, handle);
+               gasket_dev->coherent_buffer.length_bytes = 0;
+               gasket_dev->coherent_buffer.virt_base = NULL;
+               gasket_dev->coherent_buffer.phys_base = 0;
+       }
 
        kfree(gasket_dev->page_table[index]->coherent_pages);
        gasket_dev->page_table[index]->coherent_pages = NULL;