Skip to contentSkip to conversation

fs: use list_for_each_entry() for list traversing

PATCH In review Dong Fang 2 participants 4 messages Jul 30, 2013 – Jul 31, 2013

Subsystems (4)
lore
Share & tools
lore

Dong Fang

author
#0 lore raw

PATCH 1/1 fs: use list_for_each_entry() for list traversing

note: the ./checkpatch will report coding style error:
WARNING: Avoid CamelCase: <Node> ...

because i don't want to change more origin code in this patch if need be, i will send a separate patch to fix this problem.

---
 fs/aio.c              |    5 ++---
 fs/binfmt_elf.c       |   22 ++++++++--------------
 fs/binfmt_elf_fdpic.c |   34 +++++++++++++---------------------
 fs/binfmt_misc.c      |    5 ++---
 fs/dcookies.c         |   27 ++++++++++-----------------
 fs/fuse/dev.c         |    6 ++----
 fs/mbcache.c          |    6 +++---
 include/linux/aio.h   |    5 -----
 8 files changed, 40 insertions(+), 70 deletions(-)
fs/aio.c +2 -3
index 9b5ca11..909cded 100644
@@ -1223,7 +1223,7 @@ SYSCALL_DEFINE3(io_submit, aio_context_t, ctx_id, long, nr,
 static struct kiocb *lookup_kiocb(struct kioctx *ctx, struct iocb __user *iocb,
 				  u32 key)
 {
-	struct list_head *pos;
+	struct kiocb *kiocb;
 
 	assert_spin_locked(&ctx->ctx_lock);
 
@@ -1231,8 +1231,7 @@ static struct kiocb *lookup_kiocb(struct kioctx *ctx, struct iocb __user *iocb,
 		return NULL;
 
 	/* TODO: use a hash or array, this sucks. */
-	list_for_each(pos, &ctx->active_reqs) {
-		struct kiocb *kiocb = list_kiocb(pos);
+	list_for_each_entry(kiocb, &ctx->active_reqs, ki_list) {
 		if (kiocb->ki_obj.user == iocb)
 			return kiocb;
 	}
fs/binfmt_elf.c +8 -14
index 100edcc..22b9245 100644
@@ -1867,10 +1867,8 @@ static int fill_note_info(struct elfhdr *elf, int phdrs,
 			list_add(&ets->list, &info->thread_list);
 		}
 
-		list_for_each(t, &info->thread_list) {
+		list_for_each_entry(ets, &info->thread_list, list) {
 			int sz;
-
-			ets = list_entry(t, struct elf_thread_status, list);
 			sz = elf_dump_thread_status(siginfo->si_signo, ets);
 			info->thread_status_size += sz;
 		}
@@ -1933,19 +1931,16 @@ static int write_note_info(struct elf_note_info *info,
 			   struct file *file, loff_t *foffset)
 {
 	int i;
-	struct list_head *t;
+	struct elf_thread_status *ets;
 
 	for (i = 0; i < info->numnote; i++)
 		if (!writenote(info->notes + i, file, foffset))
 			return 0;
 
 	/* write out the thread status notes section */
-	list_for_each(t, &info->thread_list) {
-		struct elf_thread_status *tmp =
-				list_entry(t, struct elf_thread_status, list);
-
-		for (i = 0; i < tmp->num_notes; i++)
-			if (!writenote(&tmp->notes[i], file, foffset))
+	list_for_each_entry(ets, &info->thread_list, list) {
+		for (i = 0; i < ets->num_notes; i++)
+			if (!writenote(&ets->notes[i], file, foffset))
 				return 0;
 	}
 
@@ -1954,10 +1949,9 @@ static int write_note_info(struct elf_note_info *info,
 
 static void free_note_info(struct elf_note_info *info)
 {
-	while (!list_empty(&info->thread_list)) {
-		struct list_head *tmp = info->thread_list.next;
-		list_del(tmp);
-		kfree(list_entry(tmp, struct elf_thread_status, list));
+	struct elf_thread_status *ets, *tmp;
+	list_for_each_entry_safe(ets, tmp, &info->thread_list, list) {
+		kfree(ets);
 	}
 
 	/* Free data allocated by fill_files_note(): */
fs/binfmt_elf_fdpic.c +13 -21
index c166f32..2d00655 100644
@@ -1595,7 +1595,6 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
 	struct elf_prstatus *prstatus = NULL;	/* NT_PRSTATUS */
 	struct elf_prpsinfo *psinfo = NULL;	/* NT_PRPSINFO */
  	LIST_HEAD(thread_list);
- 	struct list_head *t;
 	elf_fpregset_t *fpu = NULL;
 #ifdef ELF_CORE_COPY_XFPREGS
 	elf_fpxregset_t *xfpu = NULL;
@@ -1604,6 +1603,7 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
 	elf_addr_t *auxv;
 	struct elf_phdr *phdr4note = NULL;
 	struct elf_shdr *shdr4extnum = NULL;
+	struct elf_thread_status *ets, *tmp;
 	Elf_Half e_phnum;
 	elf_addr_t e_shoff;
 
@@ -1643,24 +1643,21 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
 
 	if (cprm->siginfo->si_signo) {
 		struct core_thread *ct;
-		struct elf_thread_status *tmp;
 
 		for (ct = current->mm->core_state->dumper.next;
 						ct; ct = ct->next) {
-			tmp = kzalloc(sizeof(*tmp), GFP_KERNEL);
-			if (!tmp)
+			ets = kzalloc(sizeof(*ets), GFP_KERNEL);
+			if (!ets)
 				goto cleanup;
 
-			tmp->thread = ct->task;
-			list_add(&tmp->list, &thread_list);
+			ets->thread = ct->task;
+			list_add(&ets->list, &thread_list);
 		}
 
-		list_for_each(t, &thread_list) {
-			struct elf_thread_status *tmp;
+		list_for_each_entry(ets, &thread_list, list) {
 			int sz;
-
-			tmp = list_entry(t, struct elf_thread_status, list);
-			sz = elf_dump_thread_status(cprm->siginfo->si_signo, tmp);
+			sz = elf_dump_thread_status(cprm->siginfo->si_signo,
+						    ets);
 			thread_status_size += sz;
 		}
 	}
@@ -1800,12 +1797,9 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
 			goto end_coredump;
 
 	/* write out the thread status notes section */
-	list_for_each(t, &thread_list) {
-		struct elf_thread_status *tmp =
-				list_entry(t, struct elf_thread_status, list);
-
-		for (i = 0; i < tmp->num_notes; i++)
-			if (!writenote(&tmp->notes[i], cprm->file, &foffset))
+	list_for_each_entry(ets, &thread_list, list) {
+		for (i = 0; i < ets->num_notes; i++)
+			if (!writenote(&ets->notes[i], cprm->file, &foffset))
 				goto end_coredump;
 	}
 
@@ -1838,10 +1832,8 @@ end_coredump:
 	set_fs(fs);
 
 cleanup:
-	while (!list_empty(&thread_list)) {
-		struct list_head *tmp = thread_list.next;
-		list_del(tmp);
-		kfree(list_entry(tmp, struct elf_thread_status, list));
+	list_for_each_entry_safe(ets, tmp, &thread_list, list) {
+		kfree(ets);
 	}
 	kfree(phdr4note);
 	kfree(elf);
fs/binfmt_misc.c +2 -3
index 1c740e1..93a24b0 100644
@@ -69,11 +69,10 @@ static int entry_count;
  */
 static Node *check_file(struct linux_binprm *bprm)
 {
+	Node *e;
 	char *p = strrchr(bprm->interp, '.');
-	struct list_head *l;
 
-	list_for_each(l, &entries) {
-		Node *e = list_entry(l, Node, list);
+	list_for_each_entry(e, &entries, list) {
 		char *s;
 		int j;
 
fs/dcookies.c +10 -17
index ab5954b..f1af239 100644
@@ -64,22 +64,18 @@ static size_t dcookie_hash(unsigned long dcookie)
 
 static struct dcookie_struct * find_dcookie(unsigned long dcookie)
 {
-	struct dcookie_struct *found = NULL;
-	struct dcookie_struct * dcs;
-	struct list_head * pos;
-	struct list_head * list;
+	struct dcookie_struct *dcs;
+	struct list_head *head;
 
-	list = dcookie_hashtable + dcookie_hash(dcookie);
+	head = dcookie_hashtable + dcookie_hash(dcookie);
 
-	list_for_each(pos, list) {
-		dcs = list_entry(pos, struct dcookie_struct, hash_list);
+	list_for_each_entry(dcs, head, hash_list) {
 		if (dcookie_value(dcs) == dcookie) {
-			found = dcs;
-			break;
+			return dcs;
 		}
 	}
 
-	return found;
+	return NULL;
 }
 
 
@@ -283,16 +279,13 @@ static void free_dcookie(struct dcookie_struct * dcs)
 
 static void dcookie_exit(void)
 {
-	struct list_head * list;
-	struct list_head * pos;
-	struct list_head * pos2;
-	struct dcookie_struct * dcs;
+	struct list_head *head;
+	struct dcookie_struct *dcs, *tmp;
 	size_t i;
 
 	for (i = 0; i < hash_size; ++i) {
-		list = dcookie_hashtable + i;
-		list_for_each_safe(pos, pos2, list) {
-			dcs = list_entry(pos, struct dcookie_struct, hash_list);
+		head = dcookie_hashtable + i;
+		list_for_each_entry_safe(dcs, tmp, head, hash_list) {
 			list_del(&dcs->hash_list);
 			free_dcookie(dcs);
 		}
fs/fuse/dev.c +2 -4
index 1d55f94..ef74ad5 100644
@@ -1765,11 +1765,9 @@ static int fuse_notify(struct fuse_conn *fc, enum fuse_notify_code code,
 /* Look up request on processing list by unique ID */
 static struct fuse_req *request_find(struct fuse_conn *fc, u64 unique)
 {
-	struct list_head *entry;
+	struct fuse_req *req;
 
-	list_for_each(entry, &fc->processing) {
-		struct fuse_req *req;
-		req = list_entry(entry, struct fuse_req, list);
+	list_for_each_entry(req, &fc->processing, list) {
 		if (req->in.h.unique == unique || req->intr_unique == unique)
 			return req;
 	}
fs/mbcache.c +3 -3
index 8c32ef3..ae7d9de 100644
@@ -458,14 +458,14 @@ mb_cache_entry_get(struct mb_cache *cache, struct block_device *bdev,
 		   sector_t block)
 {
 	unsigned int bucket;
-	struct list_head *l;
+	struct list_head *head;
 	struct mb_cache_entry *ce;
 
 	bucket = hash_long((unsigned long)bdev + (block & 0xffffffff),
 			   cache->c_bucket_bits);
 	spin_lock(&mb_cache_spinlock);
-	list_for_each(l, &cache->c_block_hash[bucket]) {
-		ce = list_entry(l, struct mb_cache_entry, e_block_list);
+	head = &cache->c_block_hash[bucket];
+	list_for_each_entry(ce, head, e_block_list) {
 		if (ce->e_bdev == bdev && ce->e_block == block) {
 			DEFINE_WAIT(wait);
 
include/linux/aio.h +0 -5
index 1bdf965..77a9436 100644
@@ -104,11 +104,6 @@ static inline void kiocb_set_cancel_fn(struct kiocb *req,
 				       kiocb_cancel_fn *cancel) { }
 #endif /* CONFIG_AIO */
 
-static inline struct kiocb *list_kiocb(struct list_head *h)
-{
-	return list_entry(h, struct kiocb, ki_list);
-}
-
 /* for sysctl: */
 extern unsigned long aio_nr;
 extern unsigned long aio_max_nr;
Signature · 7 lines
1.7.1

--
To unsubscribe, send a message with 'unsubscribe linux-aio' in
the body to [email protected].  For more info on Linux AIO,
see: http://www.kvack.org/aio/
Don't email: <a href=mailto:"[email protected]">[email protected]</a>
maintainer
#1 lore raw
Quoted 5 lines · Dong Fang

note: the ./checkpatch will report coding style error:
WARNING: Avoid CamelCase: <Node> ...

because i don't want to change more origin code in this patch if need be, i will send a separate patch to fix this problem.

It would be a lot easier if you broke up this patch into the changes for the individual subsystems' maintainers.

-ben

--
To unsubscribe, send a message with 'unsubscribe linux-aio' in the body to [email protected]. For more info on Linux AIO,
see: http://www.kvack.org/aio/
Don't email: <a href=mailto:"[email protected]">[email protected]</a>

author
#2 lore raw
Quoted 4 lines · Benjamin LaHaise
Quoted 3 lines · Dong Fang

note: the ./checkpatch will report coding style error:
WARNING: Avoid CamelCase: <Node> ...

Quoted 8 lines
Quoted 2 lines

because i don't want to change more origin code in this patch if need be, i will send a separate patch to fix this problem.

It would be a lot easier if you broke up this patch into the changes for the individual subsystems' maintainers.

-ben

do you mean the patch series? such as [PATCH 00/xx] and each individual patch for a subsystems?

if so, i will send it later. thx

--
To unsubscribe, send a message with 'unsubscribe linux-aio' in the body to [email protected]. For more info on Linux AIO,
see: http://www.kvack.org/aio/
Don't email: <a href=mailto:"[email protected]">[email protected]</a>

maintainer
#3 lore raw
Quoted 11 lines · Dong Fang
Quoted 10 lines · Benjamin LaHaise
Quoted 5 lines · Dong Fang

note: the ./checkpatch will report coding style error:
WARNING: Avoid CamelCase: <Node> ...

because i don't want to change more origin code in this patch if need be, i will send a separate patch to fix this problem.

It would be a lot easier if you broke up this patch into the changes for the individual subsystems' maintainers.

Quoted 6 lines
Quoted 2 lines

-ben

do you mean the patch series? such as [PATCH 00/xx] and each individual patch for a subsystems?

if so, i will send it later. thx

You can drop the aio bits. That code has been removed by some of Kent's patches.

-ben

Signature · 7 lines
"Thought is the essence of where you are now."

--
To unsubscribe, send a message with 'unsubscribe linux-aio' in
the body to [email protected].  For more info on Linux AIO,
see: http://www.kvack.org/aio/
Don't email: <a href=mailto:"[email protected]">[email protected]</a>