[PATCH] drm/omap: Replace list_for_each with list_for_each_entry

Harsha Sharma harshasharmaiitr at gmail.com
Sat Oct 14 20:09:42 UTC 2017


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
- }

Signed-off-by: Harsha Sharma <harshasharmaiitr at gmail.com>
---
 drivers/gpu/drm/omapdrm/dss/display.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/omapdrm/dss/display.c b/drivers/gpu/drm/omapdrm/dss/display.c
index 42279933790e..e6f86026dd93 100644
--- a/drivers/gpu/drm/omapdrm/dss/display.c
+++ b/drivers/gpu/drm/omapdrm/dss/display.c
@@ -43,6 +43,7 @@ static int disp_num_counter;
 
 int omapdss_register_display(struct omap_dss_device *dssdev)
 {
+	struct omp_dss_device *ldev;
 	struct omap_dss_driver *drv = dssdev->driver;
 	struct list_head *cur;
 	int id;
@@ -67,13 +68,9 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
 		drv->get_timings = omapdss_default_get_timings;
 
 	mutex_lock(&panel_list_mutex);
-	list_for_each(cur, &panel_list) {
-		struct omap_dss_device *ldev = list_entry(cur,
-							 struct omap_dss_device,
-							 panel_list);
+	list_for_each_entry(ldev, &panel_list, panel_list)
 		if (strcmp(ldev->alias, dssdev->alias) > 0)
 			break;
-	}
 	list_add_tail(&dssdev->panel_list, cur);
 	mutex_unlock(&panel_list_mutex);
 	return 0;
@@ -94,12 +91,11 @@ bool omapdss_component_is_display(struct device_node *node)
 	bool found = false;
 
 	mutex_lock(&panel_list_mutex);
-	list_for_each_entry(dssdev, &panel_list, panel_list) {
+	list_for_each_entry(dssdev, &panel_list, panel_list)
 		if (dssdev->dev->of_node == node) {
 			found = true;
 			goto out;
 		}
-	}
 out:
 	mutex_unlock(&panel_list_mutex);
 	return found;
@@ -152,8 +148,7 @@ struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
 
 	omap_dss_put_device(from);
 
-	list_for_each(l, &panel_list) {
-		dssdev = list_entry(l, struct omap_dss_device, panel_list);
+	list_for_each_entry(dssdev, &panel_list, panel_list)
 		if (dssdev == from) {
 			if (list_is_last(l, &panel_list)) {
 				dssdev = NULL;
@@ -165,7 +160,6 @@ struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
 			omap_dss_get_device(dssdev);
 			goto out;
 		}
-	}
 
 	WARN(1, "'from' dssdev not found\n");
 
-- 
2.11.0



More information about the dri-devel mailing list