All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Staging: lustre: Use list_for_each_entry instead of list_for_each
@ 2016-02-25 18:17 Bhumika Goyal
  2016-02-26  6:23 ` [Outreachy kernel] " Greg KH
  2016-02-26  9:27 ` [PATCH v2] " Bhumika Goyal
  0 siblings, 2 replies; 3+ messages in thread
From: Bhumika Goyal @ 2016-02-25 18:17 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Bhumika Goyal

Use list_for_each_entry instead of list_for_each and list_entry as it
simplifies the code. Done using coccinelle:

@@
type T,T2;
identifier I1,I2;
expression e1,e2;
iterator name list_for_each_entry;
iterator name list_for_each;
@@

- T *I1;
...
- list_for_each(I1,e1)
+ list_for_each_entry(I2,e1,e2)
{
...when!=T *I1;
- I2=list_entry(I1,T2,e2);
...
}
...when!=I2;

@@
type T,T2,T3;
identifier I1,I2,I3;
expression e1,e2;
@@

- T *I1;
+ T3 *I3;
...
- list_for_each(I1,e1)
+ list_for_each_entry(I3,e1,e2)
{
...when!=T *I1;
- T3 *I3=list_entry(I1,T2,e2);
...
}

Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
---
 .../staging/lustre/lustre/obdecho/echo_client.c    |  4 +--
 drivers/staging/lustre/lustre/ptlrpc/client.c      | 31 +++++-----------------
 2 files changed, 8 insertions(+), 27 deletions(-)

diff --git a/drivers/staging/lustre/lustre/obdecho/echo_client.c b/drivers/staging/lustre/lustre/obdecho/echo_client.c
index ca87cc2..b3f152e 100644
--- a/drivers/staging/lustre/lustre/obdecho/echo_client.c
+++ b/drivers/staging/lustre/lustre/obdecho/echo_client.c
@@ -1058,12 +1058,10 @@ static int cl_echo_cancel0(struct lu_env *env, struct echo_device *ed,
 {
 	struct echo_client_obd *ec = ed->ed_ec;
 	struct echo_lock       *ecl = NULL;
-	struct list_head	     *el;
 	int found = 0, still_used = 0;
 
 	spin_lock(&ec->ec_lock);
-	list_for_each(el, &ec->ec_locks) {
-		ecl = list_entry(el, struct echo_lock, el_chain);
+	list_for_each_entry(ecl, &ec->ec_locks, el_chain) {
 		CDEBUG(D_INFO, "ecl: %p, cookie: %#llx\n", ecl, ecl->el_cookie);
 		found = (ecl->el_cookie == cookie);
 		if (found) {
diff --git a/drivers/staging/lustre/lustre/ptlrpc/client.c b/drivers/staging/lustre/lustre/ptlrpc/client.c
index 9b89068..f21c649 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/client.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/client.c
@@ -886,7 +886,7 @@ EXPORT_SYMBOL(ptlrpc_prep_fcset);
  */
 void ptlrpc_set_destroy(struct ptlrpc_request_set *set)
 {
-	struct list_head *tmp;
+	struct ptlrpc_request *req;
 	struct list_head *next;
 	int expected_phase;
 	int n = 0;
@@ -894,11 +894,7 @@ void ptlrpc_set_destroy(struct ptlrpc_request_set *set)
 	/* Requests on the set should either all be completed, or all be new */
 	expected_phase = (atomic_read(&set->set_remaining) == 0) ?
 			 RQ_PHASE_COMPLETE : RQ_PHASE_NEW;
-	list_for_each(tmp, &set->set_requests) {
-		struct ptlrpc_request *req =
-			list_entry(tmp, struct ptlrpc_request,
-				       rq_set_chain);
-
+	list_for_each_entry(req, &set->set_requests, rq_set_chain) {
 		LASSERT(req->rq_phase == expected_phase);
 		n++;
 	}
@@ -1938,16 +1934,11 @@ int ptlrpc_expire_one_request(struct ptlrpc_request *req, int async_unlink)
 int ptlrpc_expired_set(void *data)
 {
 	struct ptlrpc_request_set *set = data;
-	struct list_head *tmp;
+	struct ptlrpc_request *req;
 	time64_t now = ktime_get_real_seconds();
 
 	/* A timeout expired. See which reqs it applies to...  */
-	list_for_each(tmp, &set->set_requests) {
-		struct ptlrpc_request *req =
-			list_entry(tmp, struct ptlrpc_request,
-				       rq_set_chain);
-
-		/* don't expire request waiting for context */
+	list_for_each_entry(req, &set->set_requests, rq_set_chain) {
 		if (req->rq_wait_ctx)
 			continue;
 
@@ -1995,15 +1986,11 @@ EXPORT_SYMBOL(ptlrpc_mark_interrupted);
 void ptlrpc_interrupted_set(void *data)
 {
 	struct ptlrpc_request_set *set = data;
-	struct list_head *tmp;
+	struct ptlrpc_request *req;
 
 	CDEBUG(D_RPCTRACE, "INTERRUPTED SET %p\n", set);
 
-	list_for_each(tmp, &set->set_requests) {
-		struct ptlrpc_request *req =
-			list_entry(tmp, struct ptlrpc_request,
-				       rq_set_chain);
-
+	list_for_each_entry(req, &set->set_requests, rq_set_chain) {
 		if (req->rq_phase != RQ_PHASE_RPC &&
 		    req->rq_phase != RQ_PHASE_UNREGISTERING)
 			continue;
@@ -2018,16 +2005,12 @@ EXPORT_SYMBOL(ptlrpc_interrupted_set);
  */
 int ptlrpc_set_next_timeout(struct ptlrpc_request_set *set)
 {
-	struct list_head *tmp;
 	time64_t now = ktime_get_real_seconds();
 	int timeout = 0;
 	struct ptlrpc_request *req;
 	time64_t deadline;
 
-	list_for_each(tmp, &set->set_requests) {
-		req = list_entry(tmp, struct ptlrpc_request, rq_set_chain);
-
-		/* Request in-flight? */
+	list_for_each_entry(req, &set->set_requests, rq_set_chain) {
 		if (!(((req->rq_phase == RQ_PHASE_RPC) && !req->rq_waiting) ||
 		      (req->rq_phase == RQ_PHASE_BULK) ||
 		      (req->rq_phase == RQ_PHASE_NEW)))
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Outreachy kernel] [PATCH] Staging: lustre: Use list_for_each_entry instead of list_for_each
  2016-02-25 18:17 [PATCH] Staging: lustre: Use list_for_each_entry instead of list_for_each Bhumika Goyal
@ 2016-02-26  6:23 ` Greg KH
  2016-02-26  9:27 ` [PATCH v2] " Bhumika Goyal
  1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2016-02-26  6:23 UTC (permalink / raw)
  To: Bhumika Goyal; +Cc: outreachy-kernel

On Thu, Feb 25, 2016 at 11:47:17PM +0530, Bhumika Goyal wrote:
> Use list_for_each_entry instead of list_for_each and list_entry as it
> simplifies the code. Done using coccinelle:
> 
> @@
> type T,T2;
> identifier I1,I2;
> expression e1,e2;
> iterator name list_for_each_entry;
> iterator name list_for_each;
> @@
> 
> - T *I1;
> ...
> - list_for_each(I1,e1)
> + list_for_each_entry(I2,e1,e2)
> {
> ...when!=T *I1;
> - I2=list_entry(I1,T2,e2);
> ...
> }
> ...when!=I2;
> 
> @@
> type T,T2,T3;
> identifier I1,I2,I3;
> expression e1,e2;
> @@
> 
> - T *I1;
> + T3 *I3;
> ...
> - list_for_each(I1,e1)
> + list_for_each_entry(I3,e1,e2)
> {
> ...when!=T *I1;
> - T3 *I3=list_entry(I1,T2,e2);
> ...
> }
> 
> Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
> ---
>  .../staging/lustre/lustre/obdecho/echo_client.c    |  4 +--
>  drivers/staging/lustre/lustre/ptlrpc/client.c      | 31 +++++-----------------
>  2 files changed, 8 insertions(+), 27 deletions(-)

ALWAYS test build your patches, otherwise you will end up with grumpy
maintainers complaining you didn't test build your patches and they
broke the build.

Hint, this broke the build.  Not good :(


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2] Staging: lustre: Use list_for_each_entry instead of list_for_each
  2016-02-25 18:17 [PATCH] Staging: lustre: Use list_for_each_entry instead of list_for_each Bhumika Goyal
  2016-02-26  6:23 ` [Outreachy kernel] " Greg KH
@ 2016-02-26  9:27 ` Bhumika Goyal
  1 sibling, 0 replies; 3+ messages in thread
From: Bhumika Goyal @ 2016-02-26  9:27 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Bhumika Goyal

Use list_for_each_entry instead of list_for_each and list_entry as it
simplifies the code. Done using coccinelle:

@@
type T,T2;
identifier I1,I2;
expression e1,e2;
iterator name list_for_each_entry;
iterator name list_for_each;
@@

- T *I1;
...
- list_for_each(I1,e1)
+ list_for_each_entry(I2,e1,e2)
{
...when!=T *I1;
- I2=list_entry(I1,T2,e2);
...
}
...when!=I2;

@@
type T,T2,T3;
identifier I1,I2,I3;
expression e1,e2;
@@

- T *I1;
+ T3 *I3;
...
- list_for_each(I1,e1)
+ list_for_each_entry(I3,e1,e2)
{
...when!=T *I1;
- T3 *I3=list_entry(I1,T2,e2);
...
}

Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
---
Changes in v2:
* Test built the patch.

 .../staging/lustre/lustre/obdecho/echo_client.c    |  4 +--
 drivers/staging/lustre/lustre/ptlrpc/client.c      | 29 ++++++----------------
 2 files changed, 8 insertions(+), 25 deletions(-)

diff --git a/drivers/staging/lustre/lustre/obdecho/echo_client.c b/drivers/staging/lustre/lustre/obdecho/echo_client.c
index 3be28c5..2b13aa2 100644
--- a/drivers/staging/lustre/lustre/obdecho/echo_client.c
+++ b/drivers/staging/lustre/lustre/obdecho/echo_client.c
@@ -1060,12 +1060,10 @@ static int cl_echo_cancel0(struct lu_env *env, struct echo_device *ed,
 {
 	struct echo_client_obd *ec = ed->ed_ec;
 	struct echo_lock       *ecl = NULL;
-	struct list_head	     *el;
 	int found = 0, still_used = 0;
 
 	spin_lock(&ec->ec_lock);
-	list_for_each(el, &ec->ec_locks) {
-		ecl = list_entry(el, struct echo_lock, el_chain);
+	list_for_each_entry(ecl, &ec->ec_locks, el_chain) {
 		CDEBUG(D_INFO, "ecl: %p, cookie: %#llx\n", ecl, ecl->el_cookie);
 		found = (ecl->el_cookie == cookie);
 		if (found) {
diff --git a/drivers/staging/lustre/lustre/ptlrpc/client.c b/drivers/staging/lustre/lustre/ptlrpc/client.c
index 9b89068..1080fa1 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/client.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/client.c
@@ -886,7 +886,7 @@ EXPORT_SYMBOL(ptlrpc_prep_fcset);
  */
 void ptlrpc_set_destroy(struct ptlrpc_request_set *set)
 {
-	struct list_head *tmp;
+	struct ptlrpc_request *req;
 	struct list_head *next;
 	int expected_phase;
 	int n = 0;
@@ -894,11 +894,7 @@ void ptlrpc_set_destroy(struct ptlrpc_request_set *set)
 	/* Requests on the set should either all be completed, or all be new */
 	expected_phase = (atomic_read(&set->set_remaining) == 0) ?
 			 RQ_PHASE_COMPLETE : RQ_PHASE_NEW;
-	list_for_each(tmp, &set->set_requests) {
-		struct ptlrpc_request *req =
-			list_entry(tmp, struct ptlrpc_request,
-				       rq_set_chain);
-
+	list_for_each_entry(req, &set->set_requests, rq_set_chain) {
 		LASSERT(req->rq_phase == expected_phase);
 		n++;
 	}
@@ -1938,15 +1934,11 @@ int ptlrpc_expire_one_request(struct ptlrpc_request *req, int async_unlink)
 int ptlrpc_expired_set(void *data)
 {
 	struct ptlrpc_request_set *set = data;
-	struct list_head *tmp;
+	struct ptlrpc_request *req;
 	time64_t now = ktime_get_real_seconds();
 
 	/* A timeout expired. See which reqs it applies to...  */
-	list_for_each(tmp, &set->set_requests) {
-		struct ptlrpc_request *req =
-			list_entry(tmp, struct ptlrpc_request,
-				       rq_set_chain);
-
+	list_for_each_entry(req, &set->set_requests, rq_set_chain) {
 		/* don't expire request waiting for context */
 		if (req->rq_wait_ctx)
 			continue;
@@ -1995,15 +1987,11 @@ EXPORT_SYMBOL(ptlrpc_mark_interrupted);
 void ptlrpc_interrupted_set(void *data)
 {
 	struct ptlrpc_request_set *set = data;
-	struct list_head *tmp;
+	struct ptlrpc_request *req;
 
 	CDEBUG(D_RPCTRACE, "INTERRUPTED SET %p\n", set);
 
-	list_for_each(tmp, &set->set_requests) {
-		struct ptlrpc_request *req =
-			list_entry(tmp, struct ptlrpc_request,
-				       rq_set_chain);
-
+	list_for_each_entry(req, &set->set_requests, rq_set_chain) {
 		if (req->rq_phase != RQ_PHASE_RPC &&
 		    req->rq_phase != RQ_PHASE_UNREGISTERING)
 			continue;
@@ -2018,15 +2006,12 @@ EXPORT_SYMBOL(ptlrpc_interrupted_set);
  */
 int ptlrpc_set_next_timeout(struct ptlrpc_request_set *set)
 {
-	struct list_head *tmp;
 	time64_t now = ktime_get_real_seconds();
 	int timeout = 0;
 	struct ptlrpc_request *req;
 	time64_t deadline;
 
-	list_for_each(tmp, &set->set_requests) {
-		req = list_entry(tmp, struct ptlrpc_request, rq_set_chain);
-
+	list_for_each_entry(req, &set->set_requests, rq_set_chain) {
 		/* Request in-flight? */
 		if (!(((req->rq_phase == RQ_PHASE_RPC) && !req->rq_waiting) ||
 		      (req->rq_phase == RQ_PHASE_BULK) ||
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-02-26  9:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-25 18:17 [PATCH] Staging: lustre: Use list_for_each_entry instead of list_for_each Bhumika Goyal
2016-02-26  6:23 ` [Outreachy kernel] " Greg KH
2016-02-26  9:27 ` [PATCH v2] " Bhumika Goyal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.