From 7aaa1a92f621eec59a4ef834afefd831915a3521 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 31 Aug 2016 19:38:31 +0200 Subject: [PATCH] btrfs-progs: mkfs: use preallocated buffers for config uuids No need for dynamic allocation, the buffers are small, remove the now-useless error conditions. Signed-off-by: David Sterba --- btrfs-convert.c | 6 ++---- mkfs.c | 2 +- utils.c | 12 ++---------- utils.h | 4 ++-- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/btrfs-convert.c b/btrfs-convert.c index c10dc17..5175f1f 100644 --- a/btrfs-convert.c +++ b/btrfs-convert.c @@ -2373,10 +2373,8 @@ static int do_convert(const char *devname, int datacsum, int packing, mkfs_cfg.stripesize = blocksize; mkfs_cfg.features = features; /* New convert need these space */ - mkfs_cfg.fs_uuid = malloc(BTRFS_UUID_UNPARSED_SIZE); - mkfs_cfg.chunk_uuid = malloc(BTRFS_UUID_UNPARSED_SIZE); - *(mkfs_cfg.fs_uuid) = '\0'; - *(mkfs_cfg.chunk_uuid) = '\0'; + memset(mkfs_cfg.chunk_uuid, 0, BTRFS_UUID_UNPARSED_SIZE); + memset(mkfs_cfg.fs_uuid, 0, BTRFS_UUID_UNPARSED_SIZE); ret = make_btrfs(fd, &mkfs_cfg, &cctx); if (ret) { diff --git a/mkfs.c b/mkfs.c index adfc278..4b88987 100644 --- a/mkfs.c +++ b/mkfs.c @@ -1735,7 +1735,7 @@ int main(int argc, char **argv) } mkfs_cfg.label = label; - mkfs_cfg.fs_uuid = fs_uuid; + memcpy(mkfs_cfg.fs_uuid, fs_uuid, sizeof(mkfs_cfg.fs_uuid)); memcpy(mkfs_cfg.blocks, blocks, sizeof(blocks)); mkfs_cfg.num_bytes = dev_block_count; mkfs_cfg.nodesize = nodesize; diff --git a/utils.c b/utils.c index a31840e..45fde2e 100644 --- a/utils.c +++ b/utils.c @@ -250,16 +250,10 @@ static int setup_temp_super(int fd, struct btrfs_mkfs_config *cfg, struct btrfs_super_block *super = (struct btrfs_super_block *)super_buf; int ret; - /* - * We rely on cfg->chunk_uuid and cfg->fs_uuid to pass uuid - * for other functions. - * Caller must allocate space for them - */ - BUG_ON(!cfg->chunk_uuid || !cfg->fs_uuid); memset(super_buf, 0, BTRFS_SUPER_INFO_SIZE); cfg->num_bytes = round_down(cfg->num_bytes, cfg->sectorsize); - if (cfg->fs_uuid && *cfg->fs_uuid) { + if (*cfg->fs_uuid) { if (uuid_parse(cfg->fs_uuid, super->fsid) != 0) { error("cound not parse UUID: %s", cfg->fs_uuid); ret = -EINVAL; @@ -320,8 +314,6 @@ static int setup_temp_extent_buffer(struct extent_buffer *buf, unsigned char chunk_uuid[BTRFS_UUID_SIZE]; int ret; - /* We rely on cfg->fs_uuid and chunk_uuid to fsid and chunk uuid */ - BUG_ON(!cfg->fs_uuid || !cfg->chunk_uuid); ret = uuid_parse(cfg->fs_uuid, fsid); if (ret) return -EINVAL; @@ -1049,7 +1041,7 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg, memset(&super, 0, sizeof(super)); num_bytes = (cfg->num_bytes / cfg->sectorsize) * cfg->sectorsize; - if (cfg->fs_uuid && *cfg->fs_uuid) { + if (*cfg->fs_uuid) { if (uuid_parse(cfg->fs_uuid, super.fsid) != 0) { error("cannot not parse UUID: %s", cfg->fs_uuid); ret = -EINVAL; diff --git a/utils.h b/utils.h index da23bfc..f4e11bf 100644 --- a/utils.h +++ b/utils.h @@ -112,8 +112,8 @@ void btrfs_parse_features_to_string(char *buf, u64 flags); struct btrfs_mkfs_config { char *label; - char *fs_uuid; - char *chunk_uuid; + char fs_uuid[BTRFS_UUID_UNPARSED_SIZE]; + char chunk_uuid[BTRFS_UUID_UNPARSED_SIZE]; u64 blocks[8]; u64 num_bytes; u32 nodesize; -- 2.7.4