Skip to contentSkip to conversation

drm/tinydrm: Replace list_for_each with list_for_each_entry

PATCH Applied Harsha Sharma 4 participants 4 messages Oct 14, 2017 – Oct 21, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/tinydrm: Replace list_for_each with list_for_each_entry

Replace use of list_for_each with list_for_each_entry to simplify the code and remove variables that are used only in list_for_each. Done with following coccinelle patch:

@r@
identifier fn,i,f,p;
expression e;
iterator name list_for_each, list_for_each_entry;
type T;
@@

fn(...) {
++ T *i;
<+...
- list_for_each(p,e)
+ list_for_each_entry(i,e,f)

  {
              ...
-   T *i = list_entry(p,T,f);
                  ...

}
...+>
}

@@
identifier r.fn,r.p;
@@

fn(...) {
...
- struct list_head *p;
... when != p
}

@@
identifier r.fn,r.i,r.f;
expression r.e;
statement S;
@@

fn(...) {
<...
list_for_each_entry(i,e,f)
- {
S
- }
...>
}

@s@
identifier i,f,p;
expression e;
type T;
@@

- list_for_each(p,e)
+ list_for_each_entry(i,e,f)

  {
    ... when != T *i;
-   i = list_entry(p,T,f);
    ...

}

@@
identifier s.p;
@@

- struct list_head *p;
... when != p

@@
identifier s.i,s.f;
expression s.e;
statement S;
@@

list_for_each_entry(i,e,f)
- {
S
- }

---
 drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c +1 -3
index bd6cce093a85..bf96072d1b97 100644
@@ -414,11 +414,9 @@ tinydrm_dbg_spi_print(struct spi_device *spi, struct spi_transfer *tr,
 void _tinydrm_dbg_spi_message(struct spi_device *spi, struct spi_message *m)
 {
 	struct spi_transfer *tmp;
-	struct list_head *pos;
 	int i = 0;
 
-	list_for_each(pos, &m->transfers) {
-		tmp = list_entry(pos, struct spi_transfer, transfer_list);
+	list_for_each_entry(tmp, &m->transfers, transfer_list) {
 
 		if (tmp->tx_buf)
 			tinydrm_dbg_spi_print(spi, tmp, tmp->tx_buf, i, true);
Signature · 1 line
2.11.0
#1 lore raw
Quoted 76 lines · Harsha Sharma

Replace use of list_for_each with list_for_each_entry to simplify the code and remove variables that are used only in list_for_each. Done with following coccinelle patch:

@r@
identifier fn,i,f,p;
expression e;
iterator name list_for_each, list_for_each_entry;
type T;
@@

fn(...) {
++ T *i;
<+...
- list_for_each(p,e)
+ list_for_each_entry(i,e,f)

  {
              ...
-   T *i = list_entry(p,T,f);
                  ...

}
...+>
}

@@
identifier r.fn,r.p;
@@

fn(...) {
...
- struct list_head *p;
... when != p
}

@@
identifier r.fn,r.i,r.f;
expression r.e;
statement S;
@@

fn(...) {
<...
list_for_each_entry(i,e,f)
- {
S
- }
...>
}

@s@
identifier i,f,p;
expression e;
type T;
@@

- list_for_each(p,e)
+ list_for_each_entry(i,e,f)

  {
    ... when != T *i;
-   i = list_entry(p,T,f);
    ...

}

@@
identifier s.p;
@@

- struct list_head *p;
... when != p

@@
identifier s.i,s.f;
expression s.e;
statement S;
@@

Quoted 6 lines

list_for_each_entry(i,e,f)
- {
S
- }

Please use scripts/get_maintainers.pl to generate the list of recipients, you've missed Noralf as the tinydrm maintainer. I've added him. -Daniel

Quoted 24 lines
---
 drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c +1 -3
index bd6cce093a85..bf96072d1b97 100644
@@ -414,11 +414,9 @@ tinydrm_dbg_spi_print(struct spi_device *spi, struct spi_transfer *tr,
 void _tinydrm_dbg_spi_message(struct spi_device *spi, struct spi_message *m)
 {
 	struct spi_transfer *tmp;
-	struct list_head *pos;
 	int i = 0;
 
-	list_for_each(pos, &m->transfers) {
-		tmp = list_entry(pos, struct spi_transfer, transfer_list);
+	list_for_each_entry(tmp, &m->transfers, transfer_list) {
 
 		if (tmp->tx_buf)
 			tinydrm_dbg_spi_print(spi, tmp, tmp->tx_buf, i, true);
Signature · 1 line
2.11.0
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Reviewed-by on v1 1/1
#2 lore raw
In reply to Harsha Sharma
Quoted 76 lines · Harsha Sharma

Replace use of list_for_each with list_for_each_entry to simplify the code and remove variables that are used only in list_for_each. Done with following coccinelle patch:

@r@
identifier fn,i,f,p;
expression e;
iterator name list_for_each, list_for_each_entry;
type T;
@@

fn(...) {
++ T *i;
<+...
- list_for_each(p,e)
+ list_for_each_entry(i,e,f)

  {
              ...
-   T *i = list_entry(p,T,f);
                  ...

}
...+>
}

@@
identifier r.fn,r.p;
@@

fn(...) {
...
- struct list_head *p;
... when != p
}

@@
identifier r.fn,r.i,r.f;
expression r.e;
statement S;
@@

fn(...) {
<...
list_for_each_entry(i,e,f)
- {
S
- }
...>
}

@s@
identifier i,f,p;
expression e;
type T;
@@

- list_for_each(p,e)
+ list_for_each_entry(i,e,f)

  {
    ... when != T *i;
-   i = list_entry(p,T,f);
    ...

}

@@
identifier s.p;
@@

- struct list_head *p;
... when != p

@@
identifier s.i,s.f;
expression s.e;
statement S;
@@

Quoted 6 lines

list_for_each_entry(i,e,f)
- {
S
- }

Quoted 30 lines
---
 drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c +1 -3
index bd6cce093a85..bf96072d1b97 100644
@@ -414,11 +414,9 @@ tinydrm_dbg_spi_print(struct spi_device *spi, struct spi_transfer *tr,
 void _tinydrm_dbg_spi_message(struct spi_device *spi, struct spi_message *m)
 {
 	struct spi_transfer *tmp;
-	struct list_head *pos;
 	int i = 0;
 
-	list_for_each(pos, &m->transfers) {
-		tmp = list_entry(pos, struct spi_transfer, transfer_list);
+	list_for_each_entry(tmp, &m->transfers, transfer_list) {
 
 		if (tmp->tx_buf)
 			tinydrm_dbg_spi_print(spi, tmp, tmp->tx_buf, i, true);
Signature · 8 lines
2.11.0

-- 
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20171014202823.29230-1-harshasharmaiitr%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Signature · 1 line
Sean Paul, Software Engineer, Google / Chromium OS
#3 lore raw

Den 16.10.2017 21.19, skrev Sean Paul:

Quoted 77 lines · Harsha Sharma
Quoted 76 lines

Replace use of list_for_each with list_for_each_entry to simplify the code and remove variables that are used only in list_for_each. Done with following coccinelle patch:

@r@
identifier fn,i,f,p;
expression e;
iterator name list_for_each, list_for_each_entry;
type T;
@@

fn(...) {

++ T *i;
   <+...
- list_for_each(p,e)
+ list_for_each_entry(i,e,f)
   {
               ...
-   T *i = list_entry(p,T,f);
                   ...
    }
    ...+>
}

@@
identifier r.fn,r.p;
@@

fn(...) {
   ...
- struct list_head *p;
   ... when != p
}

@@
identifier r.fn,r.i,r.f;
expression r.e;
statement S;
@@

fn(...) {
   <...
   list_for_each_entry(i,e,f)

- {
S
- }
...>
}

@s@
identifier i,f,p;
expression e;
type T;
@@

- list_for_each(p,e)
+ list_for_each_entry(i,e,f)

   {
     ... when != T *i;
-   i = list_entry(p,T,f);
     ...

}

@@
identifier s.p;
@@

- struct list_head *p;
   ... when != p

@@
identifier s.i,s.f;
expression s.e;
statement S;
@@

Quoted 7 lines
Quoted 6 lines
   list_for_each_entry(i,e,f)

- {
S
- }

Thanks, applied to drm-misc.

Noralf.

Quoted 30 lines
Quoted 30 lines
---
  drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c +1 -3
index bd6cce093a85..bf96072d1b97 100644
@@ -414,11 +414,9 @@ tinydrm_dbg_spi_print(struct spi_device *spi, struct spi_transfer *tr,
  void _tinydrm_dbg_spi_message(struct spi_device *spi, struct spi_message *m)
  {
  	struct spi_transfer *tmp;
-	struct list_head *pos;
  	int i = 0;
 
-	list_for_each(pos, &m->transfers) {
-		tmp = list_entry(pos, struct spi_transfer, transfer_list);
+	list_for_each_entry(tmp, &m->transfers, transfer_list) {
 
  		if (tmp->tx_buf)
  			tinydrm_dbg_spi_print(spi, tmp, tmp->tx_buf, i, true);
Signature · 8 lines
2.11.0

-- 
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20171014202823.29230-1-harshasharmaiitr%40gmail.com.
For more options, visit https://groups.google.com/d/optout.