Skip to contentSkip to conversation

staging: lusture: osc: Use list_for_each_entry

PATCH Superseded Bhaktipriya Shridhar 1 participant 1 message Feb 22, 2016 Staging

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: lusture: osc: Use list_for_each_entry

In general, doubly linked lists are iterated using list_empty and list_entry functions. But it can be better written using list_for_each_entry macro.

This patch replaces the while loop containing list_empty and list_entry with list_for_each_entry and list_for_each_entry_safe(if list_del is used int the loop).

This was done with Coccinelle.

@@
expression E1;
identifier I1, I2;
type T;
iterator name list_for_each_entry;
@@

- while (list_empty(&E1) == 0)
+ list_for_each_entry (I1, &E1, I2)

{
        ...when != T *I1;
-        I1 = list_entry(E1.next, T, I2);
	...when != list_del(...);
	when != list_del_init(...);
}

@@
expression E1;
identifier I1, I2;
type T;
iterator name list_for_each_entry_safe;
@@
T *I1;
+ T *tmp;
...
- while (list_empty(&E1) == 0)
+ list_for_each_entry_safe (I1, tmp, &E1, I2)

{
	...when != T *I1;
-        I1 = list_entry(E1.next, T,I2);
	...
}
---
 drivers/staging/lustre/lustre/osc/osc_page.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/staging/lustre/lustre/osc/osc_page.c +1 -3
index 5cb0ccc..ae4b868 100644
@@ -575,14 +575,12 @@ int osc_lru_shrink(struct client_obd *cli, int target)
 	client_obd_list_lock(&cli->cl_lru_list_lock);
 	atomic_inc(&cli->cl_lru_shrinkers);
 	maxscan = min(target << 1, atomic_read(&cli->cl_lru_in_list));
-	while (!list_empty(&cli->cl_lru_list)) {
+	list_for_each_entry(opg, &cli->cl_lru_list, ops_lru) {
 		struct cl_page *page;
 
 		if (--maxscan < 0)
 			break;
 
-		opg = list_entry(cli->cl_lru_list.next, struct osc_page,
-				     ops_lru);
 		page = cl_page_top(opg->ops_cl.cpl_page);
 		if (cl_page_in_use_noref(page)) {
 			list_move_tail(&opg->ops_lru, &cli->cl_lru_list);

--
2.1.4