Skip to content

Commit 689c78a

Browse files
committed
btrfs-progs: use error_mem() macro for allocation error reports
Signed-off-by: David Sterba <[email protected]>
1 parent 069a93b commit 689c78a

24 files changed

+100
-103
lines changed

btrfs-corrupt-block.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ static int debug_corrupt_sector(struct btrfs_root *root, u64 logical, int mirror
5454

5555
buf = malloc(root->fs_info->sectorsize);
5656
if (!buf) {
57-
error_msg(ERROR_MSG_MEMORY, "allocating memory for bytenr %llu",
58-
logical);
57+
error_mem("allocating memory for bytenr %llu", logical);
5958
return -ENOMEM;
6059
}
6160

@@ -1491,7 +1490,7 @@ int main(int argc, char **argv)
14911490
del = rand_range(3);
14921491
path = btrfs_alloc_path();
14931492
if (!path) {
1494-
error_msg(ERROR_MSG_MEMORY, NULL);
1493+
error_mem(NULL);
14951494
goto out_close;
14961495
}
14971496

@@ -1617,9 +1616,7 @@ int main(int argc, char **argv)
16171616
eb = btrfs_find_create_tree_block(root->fs_info,
16181617
logical);
16191618
if (!eb) {
1620-
error_msg(ERROR_MSG_MEMORY,
1621-
"allocating extent buffer for bytenr %llu",
1622-
logical);
1619+
error_mem("allocating extent buffer for bytenr %llu", logical);
16231620
ret = 1;
16241621
goto out_close;
16251622
}

check/main.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ static int splice_shared_node(struct shared_node *src_node,
11691169
} else {
11701170
ins = malloc(sizeof(*ins));
11711171
if (!ins) {
1172-
error_msg(ERROR_MSG_MEMORY, NULL);
1172+
error_mem(NULL);
11731173
return -ENOMEM;
11741174
}
11751175
ins->cache.start = node->cache.start;
@@ -1425,7 +1425,7 @@ static int add_mismatch_dir_hash(struct inode_record *dir_rec,
14251425

14261426
hash_record = malloc(sizeof(*hash_record) + namelen);
14271427
if (!hash_record) {
1428-
error_msg(ERROR_MSG_MEMORY, "mismatch dir hash record");
1428+
error_mem("mismatch dir hash record");
14291429
return -ENOMEM;
14301430
}
14311431
memcpy(&hash_record->key, key, sizeof(*key));
@@ -5369,7 +5369,7 @@ struct chunk_record *btrfs_new_chunk_record(struct extent_buffer *leaf,
53695369

53705370
rec = calloc(1, btrfs_chunk_record_size(num_stripes));
53715371
if (!rec) {
5372-
error_msg(ERROR_MSG_MEMORY, NULL);
5372+
error_mem(NULL);
53735373
exit(-1);
53745374
}
53755375

@@ -5458,7 +5458,7 @@ static int process_device_item(struct rb_root *dev_cache,
54585458

54595459
rec = malloc(sizeof(*rec));
54605460
if (!rec) {
5461-
error_msg(ERROR_MSG_MEMORY, NULL);
5461+
error_mem(NULL);
54625462
return -ENOMEM;
54635463
}
54645464

@@ -5519,7 +5519,7 @@ btrfs_new_block_group_record(struct extent_buffer *leaf, struct btrfs_key *key,
55195519

55205520
rec = calloc(1, sizeof(*rec));
55215521
if (!rec) {
5522-
error_msg(ERROR_MSG_MEMORY, NULL);
5522+
error_mem(NULL);
55235523
exit(-1);
55245524
}
55255525

@@ -5584,7 +5584,7 @@ btrfs_new_device_extent_record(struct extent_buffer *leaf,
55845584

55855585
rec = calloc(1, sizeof(*rec));
55865586
if (!rec) {
5587-
error_msg(ERROR_MSG_MEMORY, NULL);
5587+
error_mem(NULL);
55885588
exit(-1);
55895589
}
55905590

@@ -9160,7 +9160,7 @@ static int check_chunks_and_extents(void)
91609160
bits_nr = 1024;
91619161
bits = malloc(bits_nr * sizeof(struct block_info));
91629162
if (!bits) {
9163-
error_msg(ERROR_MSG_MEMORY, NULL);
9163+
error_mem(NULL);
91649164
exit(1);
91659165
}
91669166

check/qgroup-verify.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ static int account_all_refs(int do_qgroups, u64 search_subvol)
581581
ulist_free(roots);
582582
return 0;
583583
enomem:
584-
error_msg(ERROR_MSG_MEMORY, "accounting for refs for qgroups");
584+
error_mem("accounting for refs for qgroups");
585585
return -ENOMEM;
586586
}
587587

@@ -1011,7 +1011,7 @@ static int load_quota_info(struct btrfs_fs_info *info)
10111011
count = alloc_count(&disk_key, leaf, item);
10121012
if (!count) {
10131013
ret = ENOMEM;
1014-
error_msg(ERROR_MSG_MEMORY, NULL);
1014+
error_mem(NULL);
10151015
goto out;
10161016
}
10171017

@@ -1592,7 +1592,7 @@ int print_extent_state(struct btrfs_fs_info *info, u64 subvol)
15921592

15931593
tree_blocks = ulist_alloc(0);
15941594
if (!tree_blocks) {
1595-
error_msg(ERROR_MSG_MEMORY, "allocate ulist");
1595+
error_mem("allocate ulist");
15961596
return ENOMEM;
15971597
}
15981598

cmds/device.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ static int print_device_stat_string(struct format_ctx *fctx,
624624
canonical_path = malloc(32);
625625

626626
if (!canonical_path) {
627-
error_msg(ERROR_MSG_MEMORY, "device path buffer");
627+
error_mem("device path buffer");
628628
return -ENOMEM;
629629
}
630630

@@ -678,7 +678,7 @@ static int print_device_stat_tabular(struct string_table *table, int row,
678678
canonical_path = malloc(32);
679679

680680
if (!canonical_path) {
681-
error_msg(ERROR_MSG_MEMORY, "device path buffer");
681+
error_mem("device path buffer");
682682
return -ENOMEM;
683683
}
684684

@@ -775,7 +775,7 @@ static int cmd_device_stats(const struct cmd_struct *cmd, int argc, char **argv)
775775
*/
776776
table = table_create(7, fi_args.num_devices + 2);
777777
if (!table) {
778-
error_msg(ERROR_MSG_MEMORY, NULL);
778+
error_mem(NULL);
779779
goto out;
780780
}
781781
free_table = true;

cmds/filesystem-usage.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static int add_info_to_list(struct array *chunkinfos, struct btrfs_chunk *chunk)
8484

8585
p = calloc(1, sizeof(struct chunk_info));
8686
if (!p) {
87-
error_msg(ERROR_MSG_MEMORY, NULL);
87+
error_mem(NULL);
8888
return -ENOMEM;
8989
}
9090
p->devid = devid;
@@ -94,7 +94,7 @@ static int add_info_to_list(struct array *chunkinfos, struct btrfs_chunk *chunk)
9494

9595
ret = array_append(chunkinfos, p);
9696
if (ret < 0) {
97-
error_msg(ERROR_MSG_MEMORY, NULL);
97+
error_mem(NULL);
9898
return -ENOMEM;
9999
}
100100
}
@@ -243,7 +243,7 @@ static struct btrfs_ioctl_space_args *load_space_info(int fd, const char *path)
243243

244244
sargs_orig = sargs = calloc(1, sizeof(struct btrfs_ioctl_space_args));
245245
if (!sargs) {
246-
error_msg(ERROR_MSG_MEMORY, NULL);
246+
error_mem(NULL);
247247
return NULL;
248248
}
249249

@@ -268,7 +268,7 @@ static struct btrfs_ioctl_space_args *load_space_info(int fd, const char *path)
268268
(count * sizeof(struct btrfs_ioctl_space_info)));
269269
if (!sargs) {
270270
free(sargs_orig);
271-
error_msg(ERROR_MSG_MEMORY, NULL);
271+
error_mem(NULL);
272272
return NULL;
273273
}
274274

@@ -805,7 +805,7 @@ static int load_device_info(int fd, struct array *devinfos)
805805

806806
info = calloc(1, sizeof(struct device_info));
807807
if (!info) {
808-
error_msg(ERROR_MSG_MEMORY, NULL);
808+
error_mem(NULL);
809809
return 1;
810810
}
811811
ret = array_append(devinfos, info);
@@ -927,7 +927,7 @@ static void _cmd_filesystem_usage_tabular(unsigned unit_mode,
927927

928928
matrix = table_create(ncols, nrows);
929929
if (!matrix) {
930-
error_msg(ERROR_MSG_MEMORY, NULL);
930+
error_mem(NULL);
931931
return;
932932
}
933933

cmds/inspect.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ static int print_list_chunks(struct list_chunks_ctx *ctx, const char *sortmode,
944944
/* Two rows for header and separator. */
945945
table = table_create(col_count, 2 + ctx->length);
946946
if (!table) {
947-
error_msg(ERROR_MSG_MEMORY, NULL);
947+
error_mem(NULL);
948948
return 1;
949949
}
950950
/* Print header */
@@ -1077,7 +1077,7 @@ static int cmd_inspect_list_chunks(const struct cmd_struct *cmd,
10771077
ctx.stats = calloc(ctx.size, sizeof(ctx.stats[0]));
10781078
if (!ctx.stats) {
10791079
ret = 1;
1080-
error_msg(ERROR_MSG_MEMORY, NULL);
1080+
error_mem(NULL);
10811081
goto out;
10821082
}
10831083

@@ -1101,7 +1101,7 @@ static int cmd_inspect_list_chunks(const struct cmd_struct *cmd,
11011101
lnumber = calloc(lnumber_size, sizeof(u64));
11021102
if (!lnumber) {
11031103
ret = 1;
1104-
error_msg(ERROR_MSG_MEMORY, NULL);
1104+
error_mem(NULL);
11051105
goto out;
11061106
}
11071107

@@ -1149,7 +1149,7 @@ static int cmd_inspect_list_chunks(const struct cmd_struct *cmd,
11491149
tmp = calloc(lnumber_size, sizeof(u64));
11501150
if (!tmp) {
11511151
ret = 1;
1152-
error_msg(ERROR_MSG_MEMORY, NULL);
1152+
error_mem(NULL);
11531153
goto out;
11541154
}
11551155
memcpy(tmp, lnumber, sizeof(u64) * old_size);
@@ -1168,7 +1168,7 @@ static int cmd_inspect_list_chunks(const struct cmd_struct *cmd,
11681168
* sizeof(ctx.stats[0]));
11691169
if (!ctx.stats) {
11701170
ret = 1;
1171-
error_msg(ERROR_MSG_MEMORY, NULL);
1171+
error_mem(NULL);
11721172
goto out;
11731173
}
11741174
}

cmds/qgroup.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ static struct btrfs_qgroup_comparer_set *qgroup_alloc_comparer_set(void)
662662
sizeof(struct btrfs_qgroup_comparer);
663663
set = calloc(1, size);
664664
if (!set) {
665-
error_msg(ERROR_MSG_MEMORY, NULL);
665+
error_mem(NULL);
666666
exit(1);
667667
}
668668

@@ -822,7 +822,7 @@ static struct btrfs_qgroup *get_or_add_qgroup(int fd,
822822

823823
bq = calloc(1, sizeof(*bq));
824824
if (!bq) {
825-
error_msg(ERROR_MSG_MEMORY, NULL);
825+
error_mem(NULL);
826826
return ERR_PTR(-ENOMEM);
827827
}
828828

@@ -939,7 +939,7 @@ static int update_qgroup_relation(struct qgroup_lookup *qgroup_lookup,
939939

940940
list = malloc(sizeof(*list));
941941
if (!list) {
942-
error_msg(ERROR_MSG_MEMORY, NULL);
942+
error_mem(NULL);
943943
return -ENOMEM;
944944
}
945945

@@ -1074,7 +1074,7 @@ static struct btrfs_qgroup_filter_set *qgroup_alloc_filter_set(void)
10741074
sizeof(struct btrfs_qgroup_filter);
10751075
set = calloc(1, size);
10761076
if (!set) {
1077-
error_msg(ERROR_MSG_MEMORY, NULL);
1077+
error_mem(NULL);
10781078
exit(1);
10791079
}
10801080
set->total = BTRFS_QGROUP_NFILTERS_INCREASE;
@@ -1101,7 +1101,7 @@ static int qgroup_setup_filter(struct btrfs_qgroup_filter_set **filter_set,
11011101
tmp = set;
11021102
set = realloc(set, size);
11031103
if (!set) {
1104-
error_msg(ERROR_MSG_MEMORY, NULL);
1104+
error_mem(NULL);
11051105
free(tmp);
11061106
exit(1);
11071107
}

cmds/receive.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ static int decompress_zlib(struct btrfs_receive *rctx, const char *encoded_data,
10231023
init = true;
10241024
rctx->zlib_stream = malloc(sizeof(z_stream));
10251025
if (!rctx->zlib_stream) {
1026-
error_msg(ERROR_MSG_MEMORY, "zlib stream: %m");
1026+
error_mem("zlib stream: %m");
10271027
return -ENOMEM;
10281028
}
10291029
}
@@ -1185,7 +1185,7 @@ static int decompress_and_write(struct btrfs_receive *rctx,
11851185

11861186
unencoded_data = calloc(unencoded_len, 1);
11871187
if (!unencoded_data) {
1188-
error_msg(ERROR_MSG_MEMORY, "unencoded data: %m");
1188+
error_mem("unencoded data: %m");
11891189
return -errno;
11901190
}
11911191

cmds/rescue-chunk-recover.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static struct extent_record *btrfs_new_extent_record(struct extent_buffer *eb)
9898

9999
rec = calloc(1, sizeof(*rec));
100100
if (!rec) {
101-
error_msg(ERROR_MSG_MEMORY, "extent record");
101+
error_mem("extent record");
102102
exit(1);
103103
}
104104

@@ -1476,7 +1476,7 @@ open_ctree_with_broken_chunk(struct recover_control *rc)
14761476

14771477
fs_info = btrfs_new_fs_info(1, BTRFS_SUPER_INFO_OFFSET);
14781478
if (!fs_info) {
1479-
error_msg(ERROR_MSG_MEMORY, "fs_info");
1479+
error_mem("fs_info");
14801480
return ERR_PTR(-ENOMEM);
14811481
}
14821482
fs_info->is_chunk_recover = 1;

cmds/restore.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ static int copy_one_inline(struct btrfs_root *root, int fd,
325325
ram_size = btrfs_file_extent_ram_bytes(leaf, fi);
326326
outbuf = calloc(1, ram_size);
327327
if (!outbuf) {
328-
error_msg(ERROR_MSG_MEMORY, NULL);
328+
error_mem(NULL);
329329
return -ENOMEM;
330330
}
331331

@@ -393,14 +393,14 @@ static int copy_one_extent(struct btrfs_root *root, int fd,
393393

394394
inbuf = malloc(size_left);
395395
if (!inbuf) {
396-
error_msg(ERROR_MSG_MEMORY, NULL);
396+
error_mem(NULL);
397397
return -ENOMEM;
398398
}
399399

400400
if (compress != BTRFS_COMPRESS_NONE) {
401401
outbuf = calloc(1, ram_size);
402402
if (!outbuf) {
403-
error_msg(ERROR_MSG_MEMORY, NULL);
403+
error_mem(NULL);
404404
free(inbuf);
405405
return -ENOMEM;
406406
}
@@ -1026,7 +1026,7 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
10261026
char *dir = strdup(fs_name);
10271027

10281028
if (!dir) {
1029-
error_msg(ERROR_MSG_MEMORY, NULL);
1029+
error_mem(NULL);
10301030
ret = -ENOMEM;
10311031
goto out;
10321032
}

0 commit comments

Comments
 (0)