2022-03-25 10:50:32

by Jakob Koschel

[permalink] [raw]
Subject: [PATCH] lib/logic_iomem: replace usage of found with dedicated list iterator variable

To move the list iterator variable into the list_for_each_entry_*()
macro in the future it should be avoided to use the list iterator
variable after the loop body.

To *never* use the list iterator variable after the loop it was
concluded to use a separate iterator variable instead of a
found boolean [1].

This removes the need to use a found variable and simply checking if
the variable was set, can determine if the break/goto was hit.

Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/
Signed-off-by: Jakob Koschel <[email protected]>
---
lib/logic_iomem.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/lib/logic_iomem.c b/lib/logic_iomem.c
index 8c3365f26e51..62426a6f8103 100644
--- a/lib/logic_iomem.c
+++ b/lib/logic_iomem.c
@@ -86,20 +86,20 @@ static void real_iounmap(volatile void __iomem *addr)
void __iomem *ioremap(phys_addr_t offset, size_t size)
{
void __iomem *ret = NULL;
- struct logic_iomem_region *rreg, *found = NULL;
+ struct logic_iomem_region *rreg = NULL, *iter;
int i;

mutex_lock(&regions_mtx);
- list_for_each_entry(rreg, &regions_list, list) {
- if (rreg->res->start > offset)
+ list_for_each_entry(iter, &regions_list, list) {
+ if (iter->res->start > offset)
continue;
- if (rreg->res->end < offset + size - 1)
+ if (iter->res->end < offset + size - 1)
continue;
- found = rreg;
+ rreg = iter;
break;
}

- if (!found)
+ if (!rreg)
goto out;

for (i = 0; i < MAX_AREAS; i++) {
@@ -108,7 +108,7 @@ void __iomem *ioremap(phys_addr_t offset, size_t size)
if (mapped_areas[i].ops)
continue;

- offs = rreg->ops->map(offset - found->res->start,
+ offs = rreg->ops->map(offset - rreg->res->start,
size, &mapped_areas[i].ops,
&mapped_areas[i].priv);
if (offs < 0) {

base-commit: f443e374ae131c168a065ea1748feac6b2e76613
--
2.25.1