btrfs-progs: kernel-shared: use kmalloc and kfree
All the code in kernel-shared should use the proper memory allocation helpers. Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
cdb416b72e
commit
d739e3b73a
|
@ -341,7 +341,7 @@ int btrfs_create_root(struct btrfs_trans_handle *trans,
|
|||
struct btrfs_root_item root_item = { 0 };
|
||||
int ret;
|
||||
|
||||
new_root = malloc(sizeof(*new_root));
|
||||
new_root = kmalloc(sizeof(*new_root), GFP_KERNEL);
|
||||
if (!new_root)
|
||||
return -ENOMEM;
|
||||
|
||||
|
@ -439,7 +439,7 @@ int btrfs_create_root(struct btrfs_trans_handle *trans,
|
|||
|
||||
free:
|
||||
free_extent_buffer(node);
|
||||
free(new_root);
|
||||
kfree(new_root);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -562,14 +562,14 @@ static int find_and_setup_log_root(struct btrfs_root *tree_root,
|
|||
struct btrfs_super_block *disk_super)
|
||||
{
|
||||
u64 blocknr = btrfs_super_log_root(disk_super);
|
||||
struct btrfs_root *log_root = malloc(sizeof(struct btrfs_root));
|
||||
struct btrfs_root *log_root = kmalloc(sizeof(struct btrfs_root), GFP_KERNEL);
|
||||
int ret;
|
||||
|
||||
if (!log_root)
|
||||
return -ENOMEM;
|
||||
|
||||
if (blocknr == 0) {
|
||||
free(log_root);
|
||||
kfree(log_root);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -578,7 +578,7 @@ static int find_and_setup_log_root(struct btrfs_root *tree_root,
|
|||
btrfs_super_generation(disk_super) + 1,
|
||||
btrfs_super_log_root_level(disk_super));
|
||||
if (ret) {
|
||||
free(log_root);
|
||||
kfree(log_root);
|
||||
fs_info->log_root_tree = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
@ -624,7 +624,7 @@ struct btrfs_root *btrfs_read_fs_root_no_cache(struct btrfs_fs_info *fs_info,
|
|||
ret = btrfs_find_and_setup_root(tree_root, fs_info,
|
||||
location->objectid, root);
|
||||
if (ret) {
|
||||
free(root);
|
||||
kfree(root);
|
||||
return ERR_PTR(ret);
|
||||
}
|
||||
goto insert;
|
||||
|
@ -635,7 +635,7 @@ struct btrfs_root *btrfs_read_fs_root_no_cache(struct btrfs_fs_info *fs_info,
|
|||
|
||||
path = btrfs_alloc_path();
|
||||
if (!path) {
|
||||
free(root);
|
||||
kfree(root);
|
||||
return ERR_PTR(-ENOMEM);
|
||||
}
|
||||
|
||||
|
@ -654,7 +654,7 @@ struct btrfs_root *btrfs_read_fs_root_no_cache(struct btrfs_fs_info *fs_info,
|
|||
out:
|
||||
btrfs_free_path(path);
|
||||
if (ret) {
|
||||
free(root);
|
||||
kfree(root);
|
||||
return ERR_PTR(ret);
|
||||
}
|
||||
generation = btrfs_root_generation(&root->root_item);
|
||||
|
@ -662,7 +662,7 @@ out:
|
|||
btrfs_root_bytenr(&root->root_item), generation,
|
||||
btrfs_root_level(&root->root_item));
|
||||
if (ret) {
|
||||
free(root);
|
||||
kfree(root);
|
||||
return ERR_PTR(-EIO);
|
||||
}
|
||||
insert:
|
||||
|
@ -847,20 +847,20 @@ FREE_RB_BASED_TREE(global_roots, __free_global_root);
|
|||
void btrfs_free_fs_info(struct btrfs_fs_info *fs_info)
|
||||
{
|
||||
if (fs_info->quota_root)
|
||||
free(fs_info->quota_root);
|
||||
kfree(fs_info->quota_root);
|
||||
|
||||
if (fs_info->stripe_root)
|
||||
free(fs_info->stripe_root);
|
||||
kfree(fs_info->stripe_root);
|
||||
|
||||
free_global_roots_tree(&fs_info->global_roots_tree);
|
||||
free(fs_info->tree_root);
|
||||
free(fs_info->chunk_root);
|
||||
free(fs_info->dev_root);
|
||||
free(fs_info->uuid_root);
|
||||
free(fs_info->block_group_root);
|
||||
free(fs_info->super_copy);
|
||||
free(fs_info->log_root_tree);
|
||||
free(fs_info);
|
||||
kfree(fs_info->tree_root);
|
||||
kfree(fs_info->chunk_root);
|
||||
kfree(fs_info->dev_root);
|
||||
kfree(fs_info->uuid_root);
|
||||
kfree(fs_info->block_group_root);
|
||||
kfree(fs_info->super_copy);
|
||||
kfree(fs_info->log_root_tree);
|
||||
kfree(fs_info);
|
||||
}
|
||||
|
||||
struct btrfs_fs_info *btrfs_new_fs_info(int writable, u64 sb_bytenr)
|
||||
|
@ -1082,7 +1082,7 @@ static int load_global_roots_objectid(struct btrfs_fs_info *fs_info,
|
|||
btrfs_root_level(&root->root_item),
|
||||
flags, str);
|
||||
if (ret) {
|
||||
free(root);
|
||||
kfree(root);
|
||||
break;
|
||||
}
|
||||
set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
|
||||
|
@ -1090,7 +1090,7 @@ static int load_global_roots_objectid(struct btrfs_fs_info *fs_info,
|
|||
ret = btrfs_global_root_insert(fs_info, root);
|
||||
if (ret) {
|
||||
free_extent_buffer(root->node);
|
||||
free(root);
|
||||
kfree(root);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1125,7 +1125,7 @@ static int load_global_roots_objectid(struct btrfs_fs_info *fs_info,
|
|||
set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
|
||||
root->node = btrfs_find_create_tree_block(fs_info, 0);
|
||||
if (!root->node) {
|
||||
free(root);
|
||||
kfree(root);
|
||||
ret = -ENOMEM;
|
||||
break;
|
||||
}
|
||||
|
@ -1133,7 +1133,7 @@ static int load_global_roots_objectid(struct btrfs_fs_info *fs_info,
|
|||
ret = btrfs_global_root_insert(fs_info, root);
|
||||
if (ret) {
|
||||
free_extent_buffer(root->node);
|
||||
free(root);
|
||||
kfree(root);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1194,7 +1194,7 @@ static int load_important_roots(struct btrfs_fs_info *fs_info,
|
|||
if (!btrfs_fs_compat_ro(fs_info, BLOCK_GROUP_TREE) &&
|
||||
!(btrfs_super_flags(fs_info->super_copy) &
|
||||
BTRFS_SUPER_FLAG_CHANGING_BG_TREE)) {
|
||||
free(fs_info->block_group_root);
|
||||
kfree(fs_info->block_group_root);
|
||||
fs_info->block_group_root = NULL;
|
||||
goto tree_root;
|
||||
}
|
||||
|
@ -1272,7 +1272,7 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr,
|
|||
BTRFS_UUID_TREE_OBJECTID,
|
||||
fs_info->uuid_root);
|
||||
if (ret) {
|
||||
free(fs_info->uuid_root);
|
||||
kfree(fs_info->uuid_root);
|
||||
fs_info->uuid_root = NULL;
|
||||
} else {
|
||||
set_bit(BTRFS_ROOT_TRACK_DIRTY, &fs_info->uuid_root->state);
|
||||
|
@ -1282,7 +1282,7 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr,
|
|||
BTRFS_QUOTA_TREE_OBJECTID,
|
||||
fs_info->quota_root);
|
||||
if (ret) {
|
||||
free(fs_info->quota_root);
|
||||
kfree(fs_info->quota_root);
|
||||
fs_info->quota_root = NULL;
|
||||
} else {
|
||||
fs_info->quota_enabled = 1;
|
||||
|
@ -1300,7 +1300,7 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr,
|
|||
BTRFS_RAID_STRIPE_TREE_OBJECTID,
|
||||
fs_info->stripe_root);
|
||||
if (ret) {
|
||||
free(fs_info->stripe_root);
|
||||
kfree(fs_info->stripe_root);
|
||||
fs_info->stripe_root = NULL;
|
||||
} else {
|
||||
set_bit(BTRFS_ROOT_TRACK_DIRTY, &fs_info->stripe_root->state);
|
||||
|
|
|
@ -2738,7 +2738,7 @@ static int read_one_block_group(struct btrfs_fs_info *fs_info,
|
|||
return -ENOMEM;
|
||||
ret = read_block_group_item(cache, path, &key);
|
||||
if (ret < 0) {
|
||||
free(cache);
|
||||
kfree(cache);
|
||||
return ret;
|
||||
}
|
||||
set_free_space_tree_thresholds(fs_info, cache);
|
||||
|
@ -2747,7 +2747,7 @@ static int read_one_block_group(struct btrfs_fs_info *fs_info,
|
|||
set_avail_alloc_bits(fs_info, cache->flags);
|
||||
ret = btrfs_chunk_readonly(fs_info, cache->start);
|
||||
if (ret < 0) {
|
||||
free(cache);
|
||||
kfree(cache);
|
||||
return ret;
|
||||
}
|
||||
if (ret)
|
||||
|
@ -2757,7 +2757,7 @@ static int read_one_block_group(struct btrfs_fs_info *fs_info,
|
|||
ret = update_space_info(fs_info, cache->flags, cache->length,
|
||||
cache->used, &space_info);
|
||||
if (ret < 0) {
|
||||
free(cache);
|
||||
kfree(cache);
|
||||
return ret;
|
||||
}
|
||||
cache->space_info = space_info;
|
||||
|
@ -3477,7 +3477,7 @@ static int free_block_group_cache(struct btrfs_trans_handle *trans,
|
|||
goto out;
|
||||
}
|
||||
remove_cache_extent(&fs_info->mapping_tree.cache_tree, ce);
|
||||
free(map);
|
||||
kfree(map);
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -175,7 +175,7 @@ static void free_extent_buffer_final(struct extent_buffer *eb)
|
|||
BUG_ON(eb->fs_info->cache_size < eb->len);
|
||||
eb->fs_info->cache_size -= eb->len;
|
||||
}
|
||||
free(eb);
|
||||
kfree(eb);
|
||||
}
|
||||
|
||||
static void free_extent_buffer_internal(struct extent_buffer *eb, bool free_now)
|
||||
|
@ -281,7 +281,7 @@ struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,
|
|||
return NULL;
|
||||
ret = insert_cache_extent(&fs_info->extent_cache, &eb->cache_node);
|
||||
if (ret) {
|
||||
free(eb);
|
||||
kfree(eb);
|
||||
return NULL;
|
||||
}
|
||||
list_add_tail(&eb->lru, &fs_info->lru);
|
||||
|
@ -345,7 +345,7 @@ static int read_raid56(struct btrfs_fs_info *fs_info, void *buf, u64 logical,
|
|||
}
|
||||
/* Allocate memory for the full stripe */
|
||||
for (i = 0; i < num_stripes; i++) {
|
||||
pointers[i] = malloc(BTRFS_STRIPE_LEN);
|
||||
pointers[i] = kmalloc(BTRFS_STRIPE_LEN, GFP_KERNEL);
|
||||
if (!pointers[i]) {
|
||||
ret = -ENOMEM;
|
||||
goto out;
|
||||
|
@ -414,10 +414,10 @@ static int read_raid56(struct btrfs_fs_info *fs_info, void *buf, u64 logical,
|
|||
BTRFS_STRIPE_LEN, len);
|
||||
ret = 0;
|
||||
out:
|
||||
free(failed_stripe_bitmap);
|
||||
kfree(failed_stripe_bitmap);
|
||||
for (i = 0; i < num_stripes; i++)
|
||||
free(pointers[i]);
|
||||
free(pointers);
|
||||
kfree(pointers[i]);
|
||||
kfree(pointers);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -442,12 +442,12 @@ int read_data_from_disk(struct btrfs_fs_info *info, void *buf, u64 logical,
|
|||
if (mirror > 1 && multi->type & BTRFS_BLOCK_GROUP_RAID56_MASK) {
|
||||
ret = read_raid56(info, buf, logical, read_len, mirror, multi,
|
||||
raid_map);
|
||||
free(multi);
|
||||
free(raid_map);
|
||||
kfree(multi);
|
||||
kfree(raid_map);
|
||||
*len = read_len;
|
||||
return ret;
|
||||
}
|
||||
free(raid_map);
|
||||
kfree(raid_map);
|
||||
device = multi->stripes[0].dev;
|
||||
|
||||
if (device->fd <= 0) {
|
||||
|
@ -512,7 +512,7 @@ int write_data_to_disk(struct btrfs_fs_info *info, const void *buf, u64 offset,
|
|||
this_len = min(this_len, bytes_left);
|
||||
this_len = min(this_len, (u64)info->nodesize);
|
||||
|
||||
eb = malloc(sizeof(struct extent_buffer) + this_len);
|
||||
eb = kmalloc(sizeof(struct extent_buffer) + this_len, GFP_KERNEL);
|
||||
if (!eb) {
|
||||
error_msg(ERROR_MSG_MEMORY, "extent buffer");
|
||||
ret = -ENOMEM;
|
||||
|
@ -528,7 +528,7 @@ int write_data_to_disk(struct btrfs_fs_info *info, const void *buf, u64 offset,
|
|||
stripe_len, raid_map);
|
||||
BUG_ON(ret < 0);
|
||||
|
||||
free(eb);
|
||||
kfree(eb);
|
||||
kfree(raid_map);
|
||||
raid_map = NULL;
|
||||
} else while (dev_nr < multi->num_stripes) {
|
||||
|
|
|
@ -383,12 +383,12 @@ static int __load_free_space_cache(struct btrfs_root *root,
|
|||
|
||||
ret = io_ctl_read_entry(&io_ctl, e, &type);
|
||||
if (ret) {
|
||||
free(e);
|
||||
kfree(e);
|
||||
goto free_cache;
|
||||
}
|
||||
|
||||
if (!e->bytes) {
|
||||
free(e);
|
||||
kfree(e);
|
||||
goto free_cache;
|
||||
}
|
||||
|
||||
|
@ -397,7 +397,7 @@ static int __load_free_space_cache(struct btrfs_root *root,
|
|||
if (ret) {
|
||||
fprintf(stderr,
|
||||
"Duplicate entries in free space cache\n");
|
||||
free(e);
|
||||
kfree(e);
|
||||
goto free_cache;
|
||||
}
|
||||
} else {
|
||||
|
@ -405,7 +405,7 @@ static int __load_free_space_cache(struct btrfs_root *root,
|
|||
num_bitmaps--;
|
||||
e->bitmap = kzalloc(ctl->sectorsize, GFP_NOFS);
|
||||
if (!e->bitmap) {
|
||||
free(e);
|
||||
kfree(e);
|
||||
goto free_cache;
|
||||
}
|
||||
ret = link_free_space(ctl, e);
|
||||
|
@ -413,8 +413,8 @@ static int __load_free_space_cache(struct btrfs_root *root,
|
|||
if (ret) {
|
||||
fprintf(stderr,
|
||||
"Duplicate entries in free space cache\n");
|
||||
free(e->bitmap);
|
||||
free(e);
|
||||
kfree(e->bitmap);
|
||||
kfree(e);
|
||||
goto free_cache;
|
||||
}
|
||||
list_add_tail(&e->list, &bitmaps);
|
||||
|
@ -771,7 +771,7 @@ static void try_merge_free_space(struct btrfs_free_space_ctl *ctl,
|
|||
if (right_info && !right_info->bitmap) {
|
||||
unlink_free_space(ctl, right_info);
|
||||
info->bytes += right_info->bytes;
|
||||
free(right_info);
|
||||
kfree(right_info);
|
||||
}
|
||||
|
||||
if (left_info && !left_info->bitmap &&
|
||||
|
@ -779,7 +779,7 @@ static void try_merge_free_space(struct btrfs_free_space_ctl *ctl,
|
|||
unlink_free_space(ctl, left_info);
|
||||
info->offset = left_info->offset;
|
||||
info->bytes += left_info->bytes;
|
||||
free(left_info);
|
||||
kfree(left_info);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -829,8 +829,8 @@ void __btrfs_remove_free_space_cache(struct btrfs_free_space_ctl *ctl)
|
|||
while ((node = rb_last(&ctl->free_space_offset)) != NULL) {
|
||||
info = rb_entry(node, struct btrfs_free_space, offset_index);
|
||||
unlink_free_space(ctl, info);
|
||||
free(info->bitmap);
|
||||
free(info);
|
||||
kfree(info->bitmap);
|
||||
kfree(info);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -893,8 +893,8 @@ again:
|
|||
break;
|
||||
bytes = ctl->unit;
|
||||
}
|
||||
free(e->bitmap);
|
||||
free(e);
|
||||
kfree(e->bitmap);
|
||||
kfree(e);
|
||||
goto again;
|
||||
}
|
||||
if (!prev)
|
||||
|
@ -903,7 +903,7 @@ again:
|
|||
unlink_free_space(ctl, prev);
|
||||
unlink_free_space(ctl, e);
|
||||
prev->bytes += e->bytes;
|
||||
free(e);
|
||||
kfree(e);
|
||||
link_free_space(ctl, prev);
|
||||
goto again;
|
||||
}
|
||||
|
|
|
@ -420,7 +420,7 @@ error:
|
|||
btrfs_abort_transaction(trans, ret);
|
||||
clean_dirty_buffers(trans);
|
||||
btrfs_destroy_delayed_refs(trans);
|
||||
free(trans);
|
||||
kfree(trans);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -644,10 +644,10 @@ again:
|
|||
device->writeable = 0;
|
||||
list_del(&device->dev_list);
|
||||
/* free the memory */
|
||||
free(device->name);
|
||||
free(device->label);
|
||||
free(device->zone_info);
|
||||
free(device);
|
||||
kfree(device->name);
|
||||
kfree(device->label);
|
||||
kfree(device->zone_info);
|
||||
kfree(device);
|
||||
}
|
||||
|
||||
seed_devices = fs_devices->seed;
|
||||
|
@ -658,11 +658,11 @@ again:
|
|||
orig = fs_devices;
|
||||
fs_devices = seed_devices;
|
||||
list_del(&orig->fs_list);
|
||||
free(orig);
|
||||
kfree(orig);
|
||||
goto again;
|
||||
} else {
|
||||
list_del(&fs_devices->fs_list);
|
||||
free(fs_devices);
|
||||
kfree(fs_devices);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -2797,12 +2797,12 @@ static int split_eb_for_raid56(struct btrfs_fs_info *info,
|
|||
}
|
||||
ebs[i] = eb;
|
||||
}
|
||||
free(tmp_ebs);
|
||||
kfree(tmp_ebs);
|
||||
return ret;
|
||||
clean_up:
|
||||
for (i = 0; i < num_stripes; i++)
|
||||
free(tmp_ebs[i]);
|
||||
free(tmp_ebs);
|
||||
kfree(tmp_ebs[i]);
|
||||
kfree(tmp_ebs);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -2817,11 +2817,11 @@ int write_raid56_with_parity(struct btrfs_fs_info *info,
|
|||
int alloc_size = eb->len;
|
||||
void **pointers;
|
||||
|
||||
ebs = malloc(sizeof(*ebs) * multi->num_stripes);
|
||||
pointers = malloc(sizeof(*pointers) * multi->num_stripes);
|
||||
ebs = kmalloc(sizeof(*ebs) * multi->num_stripes, GFP_KERNEL);
|
||||
pointers = kmalloc(sizeof(*pointers) * multi->num_stripes, GFP_KERNEL);
|
||||
if (!ebs || !pointers) {
|
||||
free(ebs);
|
||||
free(pointers);
|
||||
kfree(ebs);
|
||||
kfree(pointers);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
|
@ -2842,7 +2842,7 @@ int write_raid56_with_parity(struct btrfs_fs_info *info,
|
|||
}
|
||||
continue;
|
||||
}
|
||||
new_eb = malloc(sizeof(*eb) + alloc_size);
|
||||
new_eb = kmalloc(sizeof(*eb) + alloc_size, GFP_KERNEL);
|
||||
if (!new_eb) {
|
||||
ret = -ENOMEM;
|
||||
goto out_free_split;
|
||||
|
@ -2885,11 +2885,11 @@ int write_raid56_with_parity(struct btrfs_fs_info *info,
|
|||
out_free_split:
|
||||
for (i = 0; i < multi->num_stripes; i++) {
|
||||
if (ebs[i] != eb)
|
||||
free(ebs[i]);
|
||||
kfree(ebs[i]);
|
||||
}
|
||||
out:
|
||||
free(ebs);
|
||||
free(pointers);
|
||||
kfree(ebs);
|
||||
kfree(pointers);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -340,7 +340,7 @@ static int report_zones(int fd, const char *file,
|
|||
/* Allocate a zone report */
|
||||
rep_size = sizeof(struct blk_zone_report) +
|
||||
sizeof(struct blk_zone) * BTRFS_REPORT_NR_ZONES;
|
||||
rep = malloc(rep_size);
|
||||
rep = kmalloc(rep_size, GFP_KERNEL);
|
||||
if (!rep) {
|
||||
error_msg(ERROR_MSG_MEMORY, "zone report");
|
||||
exit(1);
|
||||
|
@ -386,7 +386,7 @@ static int report_zones(int fd, const char *file,
|
|||
zone[rep->nr_zones - 1].len;
|
||||
}
|
||||
|
||||
free(rep);
|
||||
kfree(rep);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -592,14 +592,14 @@ size_t btrfs_sb_io(int fd, void *buf, off_t offset, int rw)
|
|||
return (rw == WRITE ? count : 0);
|
||||
error("zoned: failed to read zone info of %u and %u: %m",
|
||||
zone_num, zone_num + 1);
|
||||
free(rep);
|
||||
kfree(rep);
|
||||
return 0;
|
||||
}
|
||||
|
||||
zones = (struct blk_zone *)(rep + 1);
|
||||
|
||||
ret = sb_log_location(fd, zones, rw, &mapped);
|
||||
free(rep);
|
||||
kfree(rep);
|
||||
/*
|
||||
* Special case: no superblock found in the zones. This case happens
|
||||
* when initializing a file-system.
|
||||
|
@ -938,7 +938,7 @@ out:
|
|||
if (!ret)
|
||||
cache->write_offset = cache->alloc_offset;
|
||||
|
||||
free(alloc_offsets);
|
||||
kfree(alloc_offsets);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue