[Nouveau] [PATCH 12/32] clk: Use list_for_each_entry_from_reverse in nvkm_cstate_find_best

Karol Herbst karolherbst at gmail.com
Fri Nov 17 00:04:16 UTC 2017


From: Karol Herbst <kherbst at redhat.com>

Signed-off-by: Karol Herbst <kherbst at redhat.com>
---
 drm/nouveau/nvkm/subdev/clk/base.c | 10 ++++------
 lib/include/nvif/list.h            |  5 +++++
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/drm/nouveau/nvkm/subdev/clk/base.c b/drm/nouveau/nvkm/subdev/clk/base.c
index 254b62f8..979f2cc3 100644
--- a/drm/nouveau/nvkm/subdev/clk/base.c
+++ b/drm/nouveau/nvkm/subdev/clk/base.c
@@ -110,18 +110,17 @@ nvkm_cstate_valid(struct nvkm_clk *clk, struct nvkm_cstate *cstate,
 
 static struct nvkm_cstate *
 nvkm_cstate_find_best(struct nvkm_clk *clk, struct nvkm_pstate *pstate,
-		      struct nvkm_cstate *start)
+		      struct nvkm_cstate *cstate)
 {
 	struct nvkm_device *device = clk->subdev.device;
 	struct nvkm_volt *volt = device->volt;
-	struct nvkm_cstate *cstate;
 	int max_volt;
 
-	if (!pstate || !start)
+	if (!pstate || !cstate)
 		return NULL;
 
 	if (!volt)
-		return start;
+		return cstate;
 
 	max_volt = volt->max_uv;
 	if (volt->max0_id != 0xff)
@@ -134,8 +133,7 @@ nvkm_cstate_find_best(struct nvkm_clk *clk, struct nvkm_pstate *pstate,
 		max_volt = min(max_volt,
 			       nvkm_volt_map(volt, volt->max2_id, clk->temp));
 
-	for (cstate = start; &cstate->head != &pstate->cstates;
-	     cstate = list_entry(cstate->head.prev, typeof(*cstate), head)) {
+	list_for_each_entry_from_reverse(cstate, &pstate->cstates, head) {
 		if (nvkm_cstate_valid(clk, cstate, max_volt, clk->temp))
 			break;
 	}
diff --git a/lib/include/nvif/list.h b/lib/include/nvif/list.h
index 6a7e15ee..91e8387b 100644
--- a/lib/include/nvif/list.h
+++ b/lib/include/nvif/list.h
@@ -355,4 +355,9 @@ list_empty(struct list_head *head)
 	     &pos->member != (head);					\
 	     pos = __container_of(pos->member.next, pos, member))
 
+#define list_for_each_entry_from_reverse(pos, head, member)		\
+	for (;								\
+	     &pos->member != (head);					\
+	     pos = __container_of(pos->member.prev, pos, member))
+
 #endif
-- 
2.15.0



More information about the Nouveau mailing list