From 355e45e64b42f02857198886fd59d3a6c274503a Mon Sep 17 00:00:00 2001 From: Leonid Lobachev Date: Mon, 23 Sep 2019 13:57:18 -0700 Subject: [PATCH] staging: gasket: page table: fixup error path allocating coherent mem Correctly clean up data structure state in gasket_alloc_coherent_memory error path, to ensure no double free on the stale pointer value. Change-Id: Ifbc426e857d6bd05a13a725f2c2fdb07dedc098c Signed-off-by: Nick Ewalt Signed-off-by: Todd Poynor --- gasket_page_table.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gasket_page_table.c b/gasket_page_table.c index 28b0042..c0a8096 100644 --- a/gasket_page_table.c +++ b/gasket_page_table.c @@ -1341,9 +1341,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;