[patch 1/1] list_for_each_entry: fs-jffs-intrep.c

[email protected] Sun, 31 Oct 2004 00:32:06 +0200
Newsgroups gmane.linux.file-systems,gmane.linux.file-systems.jffs
Message-ID <E1CO1lX-0001RZ-1I@sputnik>


Use list_for_each_entry to make code more readable.
Compile tested.

Signed-off-by: Domen Puncer <[email protected]>
Signed-off-by: Maximilian Attems <[email protected]>

---

 linux-2.6.10-rc1-max/fs/jffs/intrep.c |   22 +++++++++-------------
 1 files changed, 9 insertions(+), 13 deletions(-)

diff -puN fs/jffs/intrep.c~list-for-each-entry-fs_jffs_intrep fs/jffs/intrep.c
--- linux-2.6.10-rc1/fs/jffs/intrep.c~list-for-each-entry-fs_jffs_intrep	2004-10-24 17:04:04.000000000 +0200
+++ linux-2.6.10-rc1-max/fs/jffs/intrep.c	2004-10-24 17:04:04.000000000 +0200
@@ -1619,12 +1619,10 @@ jffs_find_file(struct jffs_control *c, _
 {
 	struct jffs_file *f;
 	int i = ino % c->hash_len;
-	struct list_head *tmp;
 
 	D3(printk("jffs_find_file(): ino: %u\n", ino));
 
-	for (tmp = c->hash[i].next; tmp != &c->hash[i]; tmp = tmp->next) {
-		f = list_entry(tmp, struct jffs_file, hash);
+	list_for_each_entry(f, &c->hash[i], hash) {
 		if (ino != f->ino)
 			continue;
 		D3(printk("jffs_find_file(): Found file with ino "
@@ -2020,13 +2018,12 @@ jffs_foreach_file(struct jffs_control *c
 	int result = 0;
 
 	for (pos = 0; pos < c->hash_len; pos++) {
-		struct list_head *p, *next;
-		for (p = c->hash[pos].next; p != &c->hash[pos]; p = next) {
-			/* We need a reference to the next file in the
-			   list because `func' might remove the current
-			   file `f'.  */
-			next = p->next;
-			r = func(list_entry(p, struct jffs_file, hash));
+		struct jffs_file *f, *next;
+
+		/* We must do _safe, because 'func' might remove the
+		   current file 'f' from the list.  */
+		list_for_each_entry_safe(f, next, &c->hash[pos], hash) {
+			r = func(f);
 			if (r < 0)
 				return r;
 			result += r;
@@ -2589,9 +2586,8 @@ jffs_print_hash_table(struct jffs_contro
 
 	printk("JFFS: Dumping the file system's hash table...\n");
 	for (i = 0; i < c->hash_len; i++) {
-		struct list_head *p;
-		for (p = c->hash[i].next; p != &c->hash[i]; p = p->next) {
-			struct jffs_file *f=list_entry(p,struct jffs_file,hash);
+		struct jffs_file *f;
+		list_for_each_entry(f, &c->hash[i], hash) {
 			printk("*** c->hash[%u]: \"%s\" "
 			       "(ino: %u, pino: %u)\n",
 			       i, (f->name ? f->name : ""),
_
-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html