summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakamath <akamath@nvidia.com>2010-06-30 16:12:21 +0530
committerGary King <gking@nvidia.com>2010-07-02 07:17:31 -0700
commit171da4c9fd3a551598844cb6850e1017a917d392 (patch)
tree395dd2db77717b0380aa541252ba3ad2d5f72eb5
parenta3562cf11c826bc29e3f76ec6c31fa8376e88524 (diff)
nvmap: carveout_free can swallow split heaps
Check if the spare buffers are contiguous before merging them. bug 697501 Change-Id: I0987dcabefdad8fe6a1c33e63c7b19cb4a017c42 Reviewed-on: http://git-master.nvidia.com/r/3360 Tested-by: Amit Kamath <akamath@nvidia.com> Reviewed-by: Gary King <gking@nvidia.com>
-rw-r--r--drivers/char/nvmap.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/drivers/char/nvmap.c b/drivers/char/nvmap.c
index 6e1830862b64..a40c4ac37e79 100644
--- a/drivers/char/nvmap.c
+++ b/drivers/char/nvmap.c
@@ -405,6 +405,9 @@ static void nvmap_split_block(struct nvmap_carveout *co,
(_co)->_list##_index = (_idx); \
} while (0);
+#define are_blocks_contiguous(_b_first, _b_next) \
+ (_b_first->base + _b_first->size == _b_next->base)
+
static void nvmap_carveout_free(struct nvmap_carveout *co, int idx)
{
struct nvmap_mem_block *b;
@@ -413,7 +416,9 @@ static void nvmap_carveout_free(struct nvmap_carveout *co, int idx)
b = BLOCK(co, idx);
- if (b->next!=-1 && co_is_free(co, b->next)) {
+ if (b->next!=-1 &&
+ co_is_free(co, b->next) &&
+ are_blocks_contiguous(b,BLOCK(co, b->next))) {
int zap = b->next;
struct nvmap_mem_block *n = BLOCK(co, zap);
b->size += n->size;
@@ -425,7 +430,9 @@ static void nvmap_carveout_free(struct nvmap_carveout *co, int idx)
nvmap_insert_block(spare, co, zap);
}
- if (b->prev!=-1 && co_is_free(co, b->prev)) {
+ if (b->prev!=-1 &&
+ co_is_free(co, b->prev) &&
+ are_blocks_contiguous(BLOCK(co, b->prev),b)) {
int zap = b->prev;
struct nvmap_mem_block *p = BLOCK(co, zap);