[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1386973529-4884-73-git-send-email-john.stultz@linaro.org>
Date: Fri, 13 Dec 2013 14:24:46 -0800
From: John Stultz <john.stultz@...aro.org>
To: LKML <linux-kernel@...r.kernel.org>
Cc: Greg KH <gregkh@...uxfoundation.org>,
Android Kernel Team <kernel-team@...roid.com>,
Sumit Semwal <sumit.semwal@...aro.org>,
Jesse Barker <jesse.barker@....com>,
Colin Cross <ccross@...roid.com>,
John Stultz <john.stultz@...aro.org>
Subject: [PATCH 072/115] ion: chunk_heap: fix leak in allocated counter
From: Colin Cross <ccross@...roid.com>
buffer->size is controlled by the outer ion layer, don't modify it
inside the heap. Instead, compute the rounded up allocated size
on demand.
Signed-off-by: Colin Cross <ccross@...roid.com>
[jstultz: modified patch to apply to staging directory]
Signed-off-by: John Stultz <john.stultz@...aro.org>
---
drivers/staging/android/ion/ion_chunk_heap.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/drivers/staging/android/ion/ion_chunk_heap.c b/drivers/staging/android/ion/ion_chunk_heap.c
index 410c08e..85fefe7 100644
--- a/drivers/staging/android/ion/ion_chunk_heap.c
+++ b/drivers/staging/android/ion/ion_chunk_heap.c
@@ -47,15 +47,15 @@ static int ion_chunk_heap_allocate(struct ion_heap *heap,
struct scatterlist *sg;
int ret, i;
unsigned long num_chunks;
+ unsigned long allocated_size;
if (ion_buffer_fault_user_mappings(buffer))
return -ENOMEM;
- num_chunks = ALIGN(size, chunk_heap->chunk_size) /
- chunk_heap->chunk_size;
- buffer->size = num_chunks * chunk_heap->chunk_size;
+ allocated_size = ALIGN(size, chunk_heap->chunk_size);
+ num_chunks = allocated_size / chunk_heap->chunk_size;
- if (buffer->size > chunk_heap->size - chunk_heap->allocated)
+ if (allocated_size > chunk_heap->size - chunk_heap->allocated)
return -ENOMEM;
table = kzalloc(sizeof(struct sg_table), GFP_KERNEL);
@@ -78,7 +78,7 @@ static int ion_chunk_heap_allocate(struct ion_heap *heap,
}
buffer->priv_virt = table;
- chunk_heap->allocated += buffer->size;
+ chunk_heap->allocated += allocated_size;
return 0;
err:
sg = table->sgl;
@@ -100,6 +100,9 @@ static void ion_chunk_heap_free(struct ion_buffer *buffer)
struct sg_table *table = buffer->priv_virt;
struct scatterlist *sg;
int i;
+ unsigned long allocated_size;
+
+ allocated_size = ALIGN(buffer->size, chunk_heap->chunk_size);
ion_heap_buffer_zero(buffer);
@@ -111,7 +114,7 @@ static void ion_chunk_heap_free(struct ion_buffer *buffer)
gen_pool_free(chunk_heap->pool, page_to_phys(sg_page(sg)),
sg_dma_len(sg));
}
- chunk_heap->allocated -= buffer->size;
+ chunk_heap->allocated -= allocated_size;
sg_free_table(table);
kfree(table);
}
--
1.8.3.2
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists