linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: quwenruo.btrfs@gmx.com, Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH v2] btrfs-progs: Replace usage of list_for_each with list_for_each_entry
Date: Thu,  7 Dec 2017 11:10:05 +0200	[thread overview]
Message-ID: <1512637805-11712-1-git-send-email-nborisov@suse.com> (raw)
In-Reply-To: <1512463189-24724-5-git-send-email-nborisov@suse.com>

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>
---
 cmds-filesystem.c |  3 +--
 disk-io.c         |  4 +---
 utils.c           |  7 +------
 volumes.c         | 15 ++++-----------
 4 files changed, 7 insertions(+), 22 deletions(-)

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 7728430f16a1..7c154589a15f 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -182,8 +182,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;
diff --git a/disk-io.c b/disk-io.c
index f5edc4796619..3d8785d5bb37 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1556,7 +1556,6 @@ static int write_dev_supers(struct btrfs_fs_info *fs_info,
 
 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 6c0d9fc1bebf..65383282b512 100644
--- a/utils.c
+++ b/utils.c
@@ -804,14 +804,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;
 	}
diff --git a/volumes.c b/volumes.c
index ce3a540578fd..2e1fb4a46465 100644
--- 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;
 	}
-- 
2.7.4


  parent reply	other threads:[~2017-12-07  9:10 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-05  8:39 [PATCH 0/7] Misc btrfs-progs cleanups/fixes Nikolay Borisov
2017-12-05  8:39 ` [PATCH 1/7] btrfs-progs: Explictly state test.sh must be executable Nikolay Borisov
2017-12-05  8:57   ` Qu Wenruo
2017-12-05  8:39 ` [PATCH 2/7] btrfs-progs: Factor out common print_device_info Nikolay Borisov
2017-12-05  9:02   ` Qu Wenruo
2017-12-05  8:39 ` [PATCH 3/7] btrfs-progs: Remove recover_get_good_super Nikolay Borisov
2017-12-05  9:10   ` Qu Wenruo
2017-12-05  8:39 ` [PATCH 4/7] btrfs-progs: Use list_for_each_entry in write_dev_all_supers Nikolay Borisov
2017-12-05  9:14   ` Qu Wenruo
2017-12-05  9:16     ` Nikolay Borisov
2017-12-07  9:10   ` Nikolay Borisov [this message]
2017-12-07  9:59     ` [PATCH v2] btrfs-progs: Replace usage of list_for_each with list_for_each_entry Qu Wenruo
2017-12-05  8:39 ` [PATCH 5/7] btrfs-progs: Document logic of btrfs_read_dev_super Nikolay Borisov
2017-12-05  9:21   ` Qu Wenruo
2017-12-05  8:39 ` [PATCH 6/7] btrfs-progs: Add test for super block recovery Nikolay Borisov
2017-12-05  9:33   ` Qu Wenruo
2017-12-05 10:04     ` Nikolay Borisov
2017-12-05 11:12       ` Qu Wenruo
2017-12-05 11:26         ` Nikolay Borisov
2017-12-05 12:13           ` Qu Wenruo
2018-01-23 15:07       ` David Sterba
2018-01-23 15:29         ` Nikolay Borisov
2018-01-23 15:39           ` David Sterba
2017-12-05  8:39 ` [PATCH 7/7] btrfs-progs: Fix super-recovery Nikolay Borisov
2017-12-05  9:35   ` Qu Wenruo
2018-01-15  9:17 ` [PATCH 0/7] Misc btrfs-progs cleanups/fixes Nikolay Borisov
2018-01-23 15:40   ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1512637805-11712-1-git-send-email-nborisov@suse.com \
    --to=nborisov@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=quwenruo.btrfs@gmx.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).