Arushi Singhal
2018-Mar-27  09:11 UTC
[Nouveau] [PATCH] gpu: drm: nouveau: Use list_for_each_entry_from_reverse
It's better to use "list_for_each_entry_from_reverse" for
iterating list
than "for loop" as it makes the code more clear to read.
This patch replace "for loop" with
"list_for_each_entry_from_reverse"
and remove "cstate" variable as it is redundant in the code.
Signed-off-by: Arushi Singhal <arushisinghal19971997 at gmail.com>
---
 drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c
b/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c
index 81c3567..5e56f74 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c
@@ -113,7 +113,6 @@ nvkm_cstate_find_best(struct nvkm_clk *clk, struct
nvkm_pstate *pstate,
 {
 	struct nvkm_device *device = clk->subdev.device;
 	struct nvkm_volt *volt = device->volt;
-	struct nvkm_cstate *cstate;
 	int max_volt;
 
 	if (!pstate || !start)
@@ -133,13 +132,12 @@ 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->list;
-	     cstate = list_prev_entry(cstate, head)) {
-		if (nvkm_cstate_valid(clk, cstate, max_volt, clk->temp))
+	list_for_each_entry_from_reverse(start, &pstate->list, head) {
+		if (nvkm_cstate_valid(clk, start, max_volt, clk->temp))
 			break;
 	}
 
-	return cstate;
+	return start;
 }
 
 static struct nvkm_cstate *
-- 
2.7.4
Ben Skeggs
2018-Mar-27  09:14 UTC
[Nouveau] [PATCH] gpu: drm: nouveau: Use list_for_each_entry_from_reverse
On 27 March 2018 at 19:11, Arushi Singhal <arushisinghal19971997 at gmail.com> wrote:> It's better to use "list_for_each_entry_from_reverse" for iterating list > than "for loop" as it makes the code more clear to read. > This patch replace "for loop" with "list_for_each_entry_from_reverse" > and remove "cstate" variable as it is redundant in the code.I would prefer to also see "start" renamed to "cstate" with this change. Ben.> > Signed-off-by: Arushi Singhal <arushisinghal19971997 at gmail.com> > --- > drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c | 8 +++----- > 1 file changed, 3 insertions(+), 5 deletions(-) > > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c > index 81c3567..5e56f74 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c > @@ -113,7 +113,6 @@ nvkm_cstate_find_best(struct nvkm_clk *clk, struct nvkm_pstate *pstate, > { > struct nvkm_device *device = clk->subdev.device; > struct nvkm_volt *volt = device->volt; > - struct nvkm_cstate *cstate; > int max_volt; > > if (!pstate || !start) > @@ -133,13 +132,12 @@ 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->list; > - cstate = list_prev_entry(cstate, head)) { > - if (nvkm_cstate_valid(clk, cstate, max_volt, clk->temp)) > + list_for_each_entry_from_reverse(start, &pstate->list, head) { > + if (nvkm_cstate_valid(clk, start, max_volt, clk->temp)) > break; > } > > - return cstate; > + return start; > } > > static struct nvkm_cstate * > -- > 2.7.4 > > _______________________________________________ > dri-devel mailing list > dri-devel at lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel
Arushi Singhal
2018-Mar-27  11:29 UTC
[Nouveau] [PATCH] gpu: drm: nouveau: Use list_for_each_entry_from_reverse
On Tue, Mar 27, 2018 at 2:44 PM, Ben Skeggs <skeggsb at gmail.com> wrote:> On 27 March 2018 at 19:11, Arushi Singhal > <arushisinghal19971997 at gmail.com> wrote: > > It's better to use "list_for_each_entry_from_reverse" for iterating list > > than "for loop" as it makes the code more clear to read. > > This patch replace "for loop" with "list_for_each_entry_from_reverse" > > and remove "cstate" variable as it is redundant in the code. > I would prefer to also see "start" renamed to "cstate" with this change. >Hello Ben Yes, using cstate is more accurate, as most of the functions are using "cstate" variable. Best Arushi> > Ben. > > > > > Signed-off-by: Arushi Singhal <arushisinghal19971997 at gmail.com> > > --- > > drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c | 8 +++----- > > 1 file changed, 3 insertions(+), 5 deletions(-) > > > > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c > b/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c > > index 81c3567..5e56f74 100644 > > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c > > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c > > @@ -113,7 +113,6 @@ nvkm_cstate_find_best(struct nvkm_clk *clk, struct > nvkm_pstate *pstate, > > { > > struct nvkm_device *device = clk->subdev.device; > > struct nvkm_volt *volt = device->volt; > > - struct nvkm_cstate *cstate; > > int max_volt; > > > > if (!pstate || !start) > > @@ -133,13 +132,12 @@ 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->list; > > - cstate = list_prev_entry(cstate, head)) { > > - if (nvkm_cstate_valid(clk, cstate, max_volt, clk->temp)) > > + list_for_each_entry_from_reverse(start, &pstate->list, head) { > > + if (nvkm_cstate_valid(clk, start, max_volt, clk->temp)) > > break; > > } > > > > - return cstate; > > + return start; > > } > > > > static struct nvkm_cstate * > > -- > > 2.7.4 > > > > _______________________________________________ > > dri-devel mailing list > > dri-devel at lists.freedesktop.org > > https://lists.freedesktop.org/mailman/listinfo/dri-devel >-------------- next part -------------- An HTML attachment was scrubbed... URL: <https://lists.freedesktop.org/archives/nouveau/attachments/20180327/5044d93c/attachment.html>
Apparently Analagous Threads
- [PATCH] gpu: drm: nouveau: Use list_for_each_entry_from_reverse
- [PATCH v2] gpu: drm: nouveau: Use list_for_each_entry_from_reverse
- [PATCH v2 2/2] gpu: drm: nouveau: Use list_{next/prev}_entry instead of list_entry
- [PATCH v2 2/2] gpu: drm: nouveau: Use list_{next/prev}_entry instead of list_entry
- [PATCH v4 13/37] clk: respect voltage limits in nvkm_cstate_prog