btrfs-progs: Replace usage of list_for_each with list_for_each_entry
authorNikolay Borisov <nborisov@suse.com>
Thu, 7 Dec 2017 09:10:05 +0000 (11:10 +0200)
committerDavid Sterba <dsterba@suse.com>
Wed, 31 Jan 2018 14:14:01 +0000 (15:14 +0100)
There are a couple of places where instead of the more succinct
list_for_each_entry the code uses list_for_each. This results in
slightly more code with no additional benefit as well as no
coherent pattern. This patch makes the code uniform. No functional
changes.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
[ remove unused variable in uuid_search ]
Signed-off-by: David Sterba <dsterba@suse.com>
cmds-filesystem.c
disk-io.c
utils.c
volumes.c

index 17d399d..25d3c0c 100644 (file)
@@ -173,7 +173,6 @@ static int match_search_item_kernel(u8 *fsid, char *mnt, char *label,
 static int uuid_search(struct btrfs_fs_devices *fs_devices, const char *search)
 {
        char uuidbuf[BTRFS_UUID_UNPARSED_SIZE];
-       struct list_head *cur;
        struct btrfs_device *device;
        int search_len = strlen(search);
 
@@ -182,8 +181,7 @@ static int uuid_search(struct btrfs_fs_devices *fs_devices, const char *search)
        if (!strncmp(uuidbuf, search, search_len))
                return 1;
 
-       list_for_each(cur, &fs_devices->devices) {
-               device = list_entry(cur, struct btrfs_device, dev_list);
+       list_for_each_entry(device, &fs_devices->devices, dev_list) {
                if ((device->label && strcmp(device->label, search) == 0) ||
                    strcmp(device->name, search) == 0)
                        return 1;
index f5edc47..3d8785d 100644 (file)
--- a/disk-io.c
+++ b/disk-io.c
@@ -1556,7 +1556,6 @@ write_err:
 
 int write_all_supers(struct btrfs_fs_info *fs_info)
 {
-       struct list_head *cur;
        struct list_head *head = &fs_info->fs_devices->devices;
        struct btrfs_device *dev;
        struct btrfs_super_block *sb;
@@ -1566,8 +1565,7 @@ int write_all_supers(struct btrfs_fs_info *fs_info)
 
        sb = fs_info->super_copy;
        dev_item = &sb->dev_item;
-       list_for_each(cur, head) {
-               dev = list_entry(cur, struct btrfs_device, dev_list);
+       list_for_each_entry(dev, head, dev_list) {
                if (!dev->writeable)
                        continue;
 
diff --git a/utils.c b/utils.c
index 3d0369f..4a16413 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -819,14 +819,9 @@ static int blk_file_in_dev_list(struct btrfs_fs_devices* fs_devices,
                const char* file)
 {
        int ret;
-       struct list_head *head;
-       struct list_head *cur;
        struct btrfs_device *device;
 
-       head = &fs_devices->devices;
-       list_for_each(cur, head) {
-               device = list_entry(cur, struct btrfs_device, dev_list);
-
+       list_for_each_entry(device, &fs_devices->devices, dev_list) {
                if((ret = is_same_loop_file(device->name, file)))
                        return ret;
        }
index ce3a540..2e1fb4a 100644 (file)
--- a/volumes.c
+++ b/volumes.c
@@ -58,10 +58,8 @@ static struct btrfs_device *__find_device(struct list_head *head, u64 devid,
                                          u8 *uuid)
 {
        struct btrfs_device *dev;
-       struct list_head *cur;
 
-       list_for_each(cur, head) {
-               dev = list_entry(cur, struct btrfs_device, dev_list);
+       list_for_each_entry(dev, head, dev_list) {
                if (dev->devid == devid &&
                    !memcmp(dev->uuid, uuid, BTRFS_UUID_SIZE)) {
                        return dev;
@@ -72,11 +70,9 @@ static struct btrfs_device *__find_device(struct list_head *head, u64 devid,
 
 static struct btrfs_fs_devices *find_fsid(u8 *fsid)
 {
-       struct list_head *cur;
        struct btrfs_fs_devices *fs_devices;
 
-       list_for_each(cur, &fs_uuids) {
-               fs_devices = list_entry(cur, struct btrfs_fs_devices, list);
+       list_for_each_entry(fs_devices, &fs_uuids, list) {
                if (memcmp(fsid, fs_devices->fsid, BTRFS_FSID_SIZE) == 0)
                        return fs_devices;
        }
@@ -234,13 +230,10 @@ void btrfs_close_all_devices(void)
 int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, int flags)
 {
        int fd;
-       struct list_head *head = &fs_devices->devices;
-       struct list_head *cur;
        struct btrfs_device *device;
        int ret;
 
-       list_for_each(cur, head) {
-               device = list_entry(cur, struct btrfs_device, dev_list);
+       list_for_each_entry(device, &fs_devices->devices, dev_list) {
                if (!device->name) {
                        printk("no name for device %llu, skip it now\n", device->devid);
                        continue;
@@ -1726,7 +1719,7 @@ int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
                return -EIO;
        }
        if (btrfs_chunk_sector_size(leaf, chunk) != sectorsize) {
-               error("invalid chunk sectorsize %llu", 
+               error("invalid chunk sectorsize %llu",
                      (unsigned long long)btrfs_chunk_sector_size(leaf, chunk));
                return -EIO;
        }