Skip to content

Commit 8e3fc85

Browse files
committed
btrfs-progs: switch memcmp() to the preferred pattern
Let's not use the ever confusing pattern of "if (!memcmp(...))" with negated operator and positive expected outcome. Signed-off-by: David Sterba <dsterba@suse.com>
1 parent b147366 commit 8e3fc85

File tree

8 files changed

+18
-19
lines changed

8 files changed

+18
-19
lines changed

btrfs-sb-mod.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static int check_csum_superblock(void *sb)
3939
btrfs_csum_data(NULL, csum_type, (unsigned char *)sb + BTRFS_CSUM_SIZE,
4040
result, BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
4141

42-
return !memcmp(sb, result, csum_size);
42+
return (memcmp(sb, result, csum_size) == 0);
4343
}
4444

4545
static void update_block_csum(void *block)

cmds/filesystem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ static int find_and_copy_seed(struct btrfs_fs_devices *seed,
581581
struct btrfs_fs_devices *cur_fs;
582582

583583
list_for_each_entry(cur_fs, fs_uuids, fs_list)
584-
if (!memcmp(seed->fsid, cur_fs->fsid, BTRFS_FSID_SIZE))
584+
if (memcmp(seed->fsid, cur_fs->fsid, BTRFS_FSID_SIZE) == 0)
585585
return copy_fs_devices(copy, cur_fs);
586586

587587
return 1;

cmds/rescue-chunk-recover.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,7 @@ open_ctree_with_broken_chunk(struct recover_control *rc)
14951495
goto out_devices;
14961496
}
14971497

1498-
UASSERT(!memcmp(disk_super->fsid, rc->fs_devices->fsid, BTRFS_FSID_SIZE));
1498+
UASSERT(memcmp(disk_super->fsid, rc->fs_devices->fsid, BTRFS_FSID_SIZE) == 0);
14991499
fs_info->sectorsize = btrfs_super_sectorsize(disk_super);
15001500
fs_info->nodesize = btrfs_super_nodesize(disk_super);
15011501
fs_info->stripesize = btrfs_super_stripesize(disk_super);
@@ -1507,9 +1507,9 @@ open_ctree_with_broken_chunk(struct recover_control *rc)
15071507
features = btrfs_super_incompat_flags(disk_super);
15081508

15091509
if (features & BTRFS_FEATURE_INCOMPAT_METADATA_UUID)
1510-
UASSERT(!memcmp(disk_super->metadata_uuid,
1510+
UASSERT(memcmp(disk_super->metadata_uuid,
15111511
fs_info->fs_devices->metadata_uuid,
1512-
BTRFS_FSID_SIZE));
1512+
BTRFS_FSID_SIZE) == 0);
15131513

15141514
btrfs_setup_root(fs_info->chunk_root, fs_info,
15151515
BTRFS_CHUNK_TREE_OBJECTID);

common/device-scan.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,7 @@ int btrfs_device_already_in_root(struct btrfs_root *root, int fd,
294294
btrfs_super_magic(&disk_super) != BTRFS_MAGIC_TEMPORARY)
295295
goto out;
296296

297-
if (!memcmp(disk_super.fsid, root->fs_info->super_copy->fsid,
298-
BTRFS_FSID_SIZE))
297+
if (memcmp(disk_super.fsid, root->fs_info->super_copy->fsid, BTRFS_FSID_SIZE) == 0)
299298
ret = 1;
300299
out:
301300
return ret;

convert/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,8 +1224,8 @@ static int do_convert(const char *devname, u32 convert_flags, u32 nodesize,
12241224
goto fail;
12251225
}
12261226
btrfs_parse_fs_features_to_string(features_buf, features);
1227-
if (!memcmp(features, &btrfs_mkfs_default_features,
1228-
sizeof(struct btrfs_mkfs_features)))
1227+
if (memcmp(features, &btrfs_mkfs_default_features,
1228+
sizeof(struct btrfs_mkfs_features)) == 0)
12291229
strcat(features_buf, " (default)");
12301230

12311231
if (convert_flags & CONVERT_FLAG_COPY_FSID) {

kernel-shared/disk-io.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,10 +1580,10 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, struct open_ctree_args *oca
15801580

15811581
/* CHECK: ignore_csum_mismatch */
15821582

1583-
ASSERT(!memcmp(disk_super->fsid, fs_devices->fsid, BTRFS_FSID_SIZE));
1583+
ASSERT(memcmp(disk_super->fsid, fs_devices->fsid, BTRFS_FSID_SIZE) == 0);
15841584
if (btrfs_fs_incompat(fs_info, METADATA_UUID))
1585-
ASSERT(!memcmp(disk_super->metadata_uuid,
1586-
fs_devices->metadata_uuid, BTRFS_FSID_SIZE));
1585+
ASSERT(memcmp(disk_super->metadata_uuid, fs_devices->metadata_uuid,
1586+
BTRFS_FSID_SIZE) == 0);
15871587

15881588
fs_info->sectorsize = btrfs_super_sectorsize(disk_super);
15891589
fs_info->nodesize = btrfs_super_nodesize(disk_super);

kernel-shared/print-tree.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,7 +1906,7 @@ static int check_csum_sblock(void *sb, int csum_size, u16 csum_type)
19061906
btrfs_csum_data(csum_type, (u8 *)sb + BTRFS_CSUM_SIZE,
19071907
result, BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
19081908

1909-
return !memcmp(sb, result, csum_size);
1909+
return (memcmp(sb, result, csum_size) == 0);
19101910
}
19111911

19121912
#define DEF_COMPAT_RO_FLAG_ENTRY(bit_name) \
@@ -2290,10 +2290,10 @@ void btrfs_print_superblock(struct btrfs_super_block *sb, int full)
22902290

22912291
uuid_unparse(sb->dev_item.fsid, buf);
22922292
if (metadata_uuid_present) {
2293-
cmp_res = !memcmp(sb->dev_item.fsid, sb->metadata_uuid,
2294-
BTRFS_FSID_SIZE);
2293+
cmp_res = (memcmp(sb->dev_item.fsid, sb->metadata_uuid,
2294+
BTRFS_FSID_SIZE) == 0);
22952295
} else {
2296-
cmp_res = !memcmp(sb->dev_item.fsid, sb->fsid, BTRFS_FSID_SIZE);
2296+
cmp_res = (memcmp(sb->dev_item.fsid, sb->fsid, BTRFS_FSID_SIZE) == 0);
22972297
}
22982298
printf("dev_item.fsid\t\t%s %s\n", buf,
22992299
cmp_res ? "[match]" : "[DON'T MATCH]");

kernel-shared/volumes.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ static struct btrfs_device *find_device(struct btrfs_fs_devices *fs_devices,
314314

315315
list_for_each_entry(dev, head, dev_list) {
316316
if (dev->devid == devid &&
317-
(!uuid || !memcmp(dev->uuid, uuid, BTRFS_UUID_SIZE))) {
317+
(!uuid || memcmp(dev->uuid, uuid, BTRFS_UUID_SIZE) == 0)) {
318318
return dev;
319319
}
320320
}
@@ -2321,7 +2321,7 @@ struct btrfs_device *btrfs_find_device(struct btrfs_fs_info *fs_info, u64 devid,
23212321
cur_devices = fs_info->fs_devices;
23222322
while (cur_devices) {
23232323
if (!fsid ||
2324-
(!memcmp(cur_devices->metadata_uuid, fsid, BTRFS_FSID_SIZE) ||
2324+
(memcmp(cur_devices->metadata_uuid, fsid, BTRFS_FSID_SIZE) == 0 ||
23252325
fs_info->ignore_fsid_mismatch)) {
23262326
device = find_device(cur_devices, devid, uuid);
23272327
if (device)
@@ -2502,7 +2502,7 @@ static int open_seed_devices(struct btrfs_fs_info *fs_info, u8 *fsid)
25022502

25032503
fs_devices = fs_info->fs_devices->seed;
25042504
while (fs_devices) {
2505-
if (!memcmp(fs_devices->fsid, fsid, BTRFS_UUID_SIZE)) {
2505+
if (memcmp(fs_devices->fsid, fsid, BTRFS_UUID_SIZE) == 0) {
25062506
ret = 0;
25072507
goto out;
25082508
}

0 commit comments

Comments
 (0)