btrfs: use malloc instead of static allocation for chunk map
authorDu, Alek <alek.du@intel.com>
Tue, 29 Dec 2009 07:58:06 +0000 (23:58 -0800)
committerH. Peter Anvin <hpa@zytor.com>
Tue, 29 Dec 2009 15:56:10 +0000 (07:56 -0800)
Now when we have malloc() available, use it instead of static allocation.

Signed-off-by: Alek Du <alek.du@intel.com>
LKML-Reference: <1262073486-21321-1-git-send-email-alek.du@intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
core/fs/btrfs/btrfs.c
core/fs/btrfs/btrfs.h

index ee420b1..31e24f7 100644 (file)
@@ -86,6 +86,14 @@ static void insert_map(struct btrfs_chunk_map_item *item)
        int slot;
        int i;
 
+       if (chunk_map.map == NULL) { /* first item */
+               chunk_map.map_length = BTRFS_MAX_CHUNK_ENTRIES;
+               chunk_map.map = (struct btrfs_chunk_map_item *)
+                       malloc(chunk_map.map_length * sizeof(*chunk_map.map));
+               chunk_map.map[0] = *item;
+               chunk_map.cur_length = 1;
+               return;
+       }
        ret = bin_search(chunk_map.map, sizeof(*item), item,
                        (cmp_func)btrfs_comp_chunk_map, 0,
                        chunk_map.cur_length, &slot);
index 9ee9092..8ec8afe 100644 (file)
@@ -197,7 +197,7 @@ struct btrfs_chunk_map_item {
 };
 
 struct btrfs_chunk_map {
-       struct btrfs_chunk_map_item map[BTRFS_MAX_CHUNK_ENTRIES];
+       struct btrfs_chunk_map_item *map;
        u32 map_length;
        u32 cur_length;
 };